All threads / Link to a method in my model

Ask A Question

Notifications

You’re not receiving notifications from this thread.

Link to a method in my model

Simon P asked in Rails

Hi

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?

Thanks

Simon

Fresh start to a new days and nailed this myself:

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

Join the discussion

Want to stay up-to-date with Ruby on Rails?

Join 37,629+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    logo Created with Sketch.

    Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

    © 2020 GoRails, LLC. All rights reserved.