Best way to highlight current page in Rails 3? — apply a css class to links conditionally

后端 未结 8 1767
野趣味
野趣味 2020-12-04 14:25

For the following code:

<%= link_to \"Some Page\", some_path %>

How do I apply a css class current using the

8条回答
  •  半阙折子戏
    2020-12-04 14:52

    A variant to Eric Boehs solution (the most robust one IMHO), if you are linking directly to an object of the class (i.e. you don't show the index), with an added application helper:

    def booking_link
     Booking.find(8)
    end
    

    You can use the following in the view (the dd is used in the context of zurb foundation)

    <%= content_tag :dd, link_to(t('hints.book'), booking_link), class: active_class?(booking_path) %>-
    

提交回复
热议问题