ruby on rails - How can I refactor these unless statements to make the block more efficient? -


I'm trying to add a "current" class, if the "order" URL is the absolute (i.e. example .com / photos? Order = views). I need some help, it should be restructured, so it is not very fun.

  Parameters up to <%: command]! = 'Made_t'% & gt; & Lt;% = link_to "Posted recently", photos_path ,: class = & gt; 'Current'% & gt; & Lt;% else% & gt; & Lt;% = link_to "Posted recently", photos_path%> & Lt;% end% & gt; & Lt; Span class = "pipe" & gt; | & Lt; / Span & gt; & Lt;% Params [until: order]! = 'Comments'% & gt; & Lt;% = link_to "Most Commented", photos_path + "? Order = comments" ,: class = & gt; 'Current'% & gt; & Lt;% else% & gt; & Lt;% = link_to "Most commented", photos_path + "? Order = comments"%> & Lt;% end% & gt; & Lt; Span class = "pipe" & gt; | & Lt; / Span & gt; & Lt;% Params [: Order] until! = 'View'% & gt; & Lt;% = link_to "Most Viewed", photos_path + "? Order = views" ,: class = & gt; 'Current'% & gt; & Lt;% else% & gt; & Lt;% = link_to "Most Visited", photos_path + "? Order = View"%> & Lt;% end% & gt;  

For example, you can use the assistant:

  & lt;% = link_to_photo_v_order 'made_t', "recently posted"%> & Lt; Span class = "pipe" & gt; | & Lt; / Span & gt; & Lt;% = link_to_photos_with_order 'Comments', "Most Commented"% & gt; & Lt; Span class = "pipe" & gt; | & Lt; / Span & gt; & Lt;% = link_to_photos_with_order 'Ideas', 'Most Viewed'% & gt;  

  def link_to_photos_with_order order_by, title url = photos_path (: order = & gt; (order_by! = 'Created_at'? Order_by: zero)) when Not far the parameters: [Order]! = Title, URL for order-link ,: class => The other way is to use the hash -b => title, but this is a yug 

/ Html>

Comments