Conditionally setting CSS style from ruby controller

前端 未结 5 1707
没有蜡笔的小新
没有蜡笔的小新 2021-02-01 11:07

I\'m trying to dynamically change (if it got clicked) a normal table header (which is a link) to another defined CSS class \'th.hilite\'. This link simply sorts this column and

5条回答
  •  天命终不由人
    2021-02-01 11:34

    You can bind it from the view directly:

    %th{:class => ("hilite" if @sort == "title")}= link_to 'Movie Title'...

    However, you will also have to declare the @sort instance variable in your controller, and set it to either title or release, according to which column you are sorting. (i.e. @sort = params[:sort])

提交回复
热议问题