0

The REST service expects me as the client app to pass him a URL with a structure like this:

http://localhost:3001/generic_rates?chart=medications&brand_name=advil&dose=9mg&form=tablet

so in the controller he is accessing them like params[:brand_name]

But how I should produce something like this in my view and set it to him? Does Rails have methods that form a URL for us?

1
  • 1
    Show output of rake routes Commented May 23, 2013 at 17:29

2 Answers 2

2

Rails creates helpers for routes. Like in the comments, run rake routes in terminal and you will get a four columns output: Helper method | HTTP Method | URL | Controller#Action.

To use the "Helper method" you need to append _path o _url. Probably you have a generic_rates_path.

To get a link to the URL you want:

= link_to 'Generic Rates', generic_rates_path(chart: @chart, brand_name: @brand.name...)

So, you can pass params with the helper.

Hope this helps!

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

Comments

1

From the Ruby on Rails docs:

link_to "Ruby on Rails search", :controller => "searches", :query => "ruby on rails"
# => <a href="/searches?query=ruby+on+rails">Ruby on Rails search</a>

link_to "Nonsense search", searches_path(:foo => "bar", :baz => "quux")
# => <a href="/searches?foo=bar&amp;baz=quux">Nonsense search</a>

Comments

Your Answer

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