1

I am trying to create a route like this using Ruby on rails:

 get '/products/:store/:destination/:category/'

Sorry if this is trivial, but I'd need to know how build a controller for this, and it would be helpful to know how to pass the listed parameters from the views to the controller using an helper method such as 'link_to'. Thank you very much

1 Answer 1

1

You can create the url by passing appropriate attributes :

<%=link_to 'Something Awesome', "/products/#{store}/#{destination}/#{category}"%>

I'm not sure what your use case is and how you plan to pass those parameters in the url. But, you might want to create a form_tag instead for it's a much cleaner solution.

<%form_tag your_awesome_action_path do |f|%>
  <%=text_field_tag :store%>
  <%=text_field_tag :destination%>
  <%=text_field_tag :category%>
  <%=submit_tag 'Submit'%>
<%end%>

where, your_awesome_url is path to the controller action that will process the form. you'll need an action your_awesome_action in the products controller and a corresponding route in routes.rb :

match 'your_awesome_action' => 'products#your_awesome_action'.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.