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?
-
You can do it if you pass the javascript variable as a parameter to your controller and set the variableusha– usha2014-04-22 04:03:00 +00:00Commented Apr 22, 2014 at 4:03
-
You can use "view helpers" for this approach..Raj Adroit– Raj Adroit2014-04-22 06:35:00 +00:00Commented Apr 22, 2014 at 6:35
Add a comment
|
2 Answers
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