0
Rails 5.0.0.rc1
Ruby 2.2.5 (can update to latest)

I'd like to think this is possible. I'm making a get request that when a field is selected then the user presses the next button, it goes to another page and that page's url looks like:

http://localhost:3000/food/r/new?utf8=%E2%9C%93&id=2&food=Apple&commit=Next

This looks ugly, to me. Could it be more nicer to look like this:

http://localhost:3000/food/r/new/<some_random_short_string/<name-of-page>

I'd imagine the some_random_short_string would be a hash then in the controller would have something like:

hash = params[:some_random_short_string]
hash[:food] #=> "Apple"
etc...

Not sure how to go about this. Any pointers, please?

4
  • Maybe friendly_id gem could help? Commented Jun 5, 2016 at 7:39
  • @seph Not really. I may end up, in the url, with many field names. Commented Jun 5, 2016 at 7:40
  • Hashing (using MD5 or SHA1) is a one-way trip. You hashes your original data, and you never get them back. Commented Jun 5, 2016 at 7:53
  • @Aetherus I have figured, thanks. Found a simple way for this. I forgot the difference between get and post ;) Commented Jun 5, 2016 at 7:59

1 Answer 1

1

Rather than deleting my question, I'll answer it as I will come back to it one day.

'get' exposes data in the url so I went for post. No need for a hash just use params to store the values.

Once page is submitted, the url will look like: http://localhost:3000/food/r/new. In the controller, you use your params:

@selected_food = params[:food]

new.html.erb:

<%= @selected_food %> #=> Apple 
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.