简体   繁体   中英

Ruby on Rails: passing value from view to controller

I am new to Rails. I have calculated some value in a javascript based upon user inputs and now I want to set a variable present in controller function to the calculate value. Is it possible to do so or is there a better approach?

Are you sending a param with the javascript? Then just set:

@variable = params[:calculate]

Set the value into a hidden_field_tag in side the form,then you can get the value in params .

Ex.

In js script

document.getElementsByName('js_hidden').value = 1111;

then the value will assign into the hidden_field_tag

like

hidden_field_tag 'from_js',1111,:id=>"js_hidden"

then

in your controller you can get params[:from_js] .

More details click here

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