Home>

What i am doing is almost the same as this page.I want to create individual links with ransack
I am making a search function with ransack, and I want to jump to the search result when I click the div containing the image and text.

code

shops_controller

def index
  @q = Shop.ransack (params [: q])
  @shops = @ q.result (distinct: true) .paginate (page: params [: page])
end


view

<% = link_to controller: "shops", action: "index", q: {address_cont:'Tokyo'}, class: "Class I want to reflect" do%>
  
     image 
     text 
  
<% end%>


When I click the image and text div surrounded by link_to, it jumps to the search result of "Tokyo" properly, but the class is not reflected and css does not work.
I think the grammar of link_to is wrong, but please teach me how to write it correctly.

  • Answer # 1

    I think the grammar of link_to is wrong

    It is grammatically valid, but if it is left as it isclassAlsoPart of the URLWill be incorporated into.

    Let's separate the hash for the URL and the other.

    <% = link_to ({controller: "shops", action: "index", q: {address_cont:'Tokyo'}}, {class: "class you want to reflect"}) do%>