简体   繁体   中英

Ruby on Rails - Passing parameters to set in url

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?

# 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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM