I’m challenging a annoying problem in rails.
I have a view and I’m trying to render a partial, but only when @prev_activity != message.about like this:
<%= @prev_activity != message.about ? render(:partial => "dashboards/stream_activity", :locals => { :activity => message.about }) : render(:text => "") %>
In dashboards/_stream_activity.html.erb I render some content and also set previous activity variable:
<% @prev_activity = activity %>
It does not work because rails render dashboards/_stream_activity.html.erb before @prev_activity != message.about is checked, so @prev_activity is equal to message.about.
Is there any way to solve this one?
I’ve finally found solution for that. In view where I render the collection I set
@prev_activitytonil.than it works like expected in dashboards/_stream_message.html.erb:
dashboards/_stream_activity.html.erb:
setting
@prev_activitytonilin controller didn’t work as well as all the other solutions posted here.