开发者

Action view error

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开发者_JAVA技巧.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?


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.


Instead of Time.now try creating a time object:

today = Time.new

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜