I have a website with a form for location on the front page. I want to auto-populate the form with values based on a URL string. How can I do this in rails?
For example, I would like the form to show with the value New York when the user arrives on the front page based on something like: website.com?city=”New York”
How best to implement this in rails?
First of all, you can get the current request url, everything is here : How do I get the current absolute URL in Ruby on Rails?
Then you just have to “parse” it :
Will return “New York” with a url like
website.com?city="New York"(Not sure about this one but maybe you can get it only with params[:city], I just don’t think
paramsis available in a view)The rest depends on the structure of your form…