Adding dynamic attributes to HAML tag using helper method in rails -
so figured out way of doing this, there easier way it? want add .class after %th tag if params[:sort] == sortby, need have rest of haml in helper-method?
this helper method helper.rb file:
def yellow?(sortby,name,id) haml_tag :th, class: "#{'hilite' if params[:sort]== sortby}" haml_concat link_to name, movies_path(sort: sortby),{:id => id} end end this haml file:
%tr - yellow?("title","movie title","title_header") %th rating
have tried solution:
%tr %th{ :class => if params[:sort] == 'sortby' 'hilite' end } = link_to "movie title", movies_path(:sort => 'title'), :id => "title_header" %th rating you can move statement: if params[:sort] == 'sortby' 'hilite' end helper. take similar answer: haml 2 spaces issue.
Comments
Post a Comment