Reputation: 97
this maybe is an usual and easy ask to answer but Im new in this. I have my route and view asociated to my webtool ready and working, the route is like this "mysite.com/calculator". Its about some charts which change their values depends of choices in some levers (1 up to 4). I need to add the functionality to navigate at some url like "mysite.com/calculator/1113231" where the numbers are the choices preselected. If i can do some like that I'll need to get the numbers and set the levers by JS i think. Some advise and/or example of how to do this?
Upvotes: 0
Views: 1159
Reputation: 359
# everything in parenthesis after the path
# helper is added as a hash to the URL
# parameters
calculator_path(number1: 80085, number2: 58008)
...will translate to
# parameters added to a URL is noted
# by the '?' followed by each parameter
# assigned and it's value
/calculator?number1=80085&number2=58008
Then you can pull the params down in your controller
first_number = params[:number1]
second_number = params[:number2]
If you want to add a dynamic value, use a variable that gets assignment from somewhere else in your code....
calculator_path(x: @rdm_num_1, y: @rnd_num_2)
Upvotes: 1