Reputation: 33
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?
Upvotes: 1
Views: 129
Reputation: 1714
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
Upvotes: 0
Reputation: 1567
Are you sending a param with the javascript? Then just set:
@variable = params[:calculate]
Upvotes: 2