Reputation: 12072
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?
Upvotes: 0
Views: 198
Reputation: 12072
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
Upvotes: 1