views:

34

answers:

2

i have some code ..

<% @articles.each do |article|%>
   <%= link_to h(article.title), show_article_path({:id => article.permalink})%></font>
<% end %>

i have 3 action use this code, but i want to get result only between start_publish and finish_publish or finish publish blank and (only in one action for example Action Posting), then i added code like this

<% @articles.each do |article|%>
  <% if (Time.now >= article.posted_at) && (Time.now <= finish_publish || article.finis_publish.blank?) && (params[:action] =>'posting')%>
    <%= link_to h(article.title), show_article_path({:id => article.permalink})%>
  <% else %>
    <%= link_to h(article.title), show_article_path({:id => article.permalink})%>
  <% end %>
<% end %>

this is worked when fields arent blank. the problem is when finish publish blank, appear error message. it said .. Time.now value nil. and i think "&& (params[:action] =>'posting')%>" is error.

please have You suggestion for this case?

A: 

Instead of Time.now try creating a time object:

today = Time.new

and then check against "today" and not "Time.now"

marcgg
+1  A: 

I think you mean to do params[:action] == "posting" The => syntax is known as the hash rocket, which assigns a key to a value inside a hash.

Ryan Bigg