Skip to main content
Ask A Question
You’re not receiving notifications from this thread.

Link to a method in my model

Rails • Asked by Simon P


I have a method called Search(search) in my model which is called from my controller. This works fine when I enter a search term in an input box in my view.

What I now want to do is create a link for a preset search term that pass the preset search term to the method.

Something like:

<%= link_to "Search Term", articles_search_path("Search Term") %>

How should this link look and what do I need in my controller to pass this to my model?



Fresh start to a new days and nailed this myself:

<%= link_to "Search Term", articles_path(search: "Search Term")

Login or Create An Account to join the conversation.

Subscribe to the newsletter

Join 29,237+ developers who get early access to new screencasts, articles, guides, updates, and more.

    By clicking this button, you agree to the GoRails Terms of Service and Privacy Policy.

    More of a social being? We're also on Twitter and YouTube.