0

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?

1 Answer 1

2

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 :

<% city = request.fullpath.split('=').last %>

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 params is available in a view)

The rest depends on the structure of your form...

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.