All I want to do is update a text field on my page with a value when my Rails remote form is submitted.
All the source code be found at github here https://github.com/iamliamnorton/fasdac
The form is on the index page…
Controller code…
def index
@calculator = Calculator.new(params[:calculator])
if @calculator.valid?
respond_to do |format|
format.html { redirect_to calculator_path(:calculator => params[:calculator]), :notice => 'Calculation was successfully completed.' }
format.js
end
else
respond_to do |format|
format.html { redirect_to calculator_path(:calculator => params[:calculator]), :alert => "Calculation was not successfully completed. #{@calculator.errors.full_messages.to_sentence}" }
format.js
end
end
My input form
<%= form_for(@calculator, :url => calculator_path, :remote => true) do |f| %>
...
<% end %>
And the index.js.erb
$("#result").value = "SUCCESS!";
I’m trying to update a input text field with name and id ‘result’. I cannot get this working, I’ve tried many different variants in the index.js.erb but cannot get it working. What am I doing wrong?
It looks like the data is being sent to the controller as I can see in the server console
...
Processing by CalculatorController#index as JS
...
But I can’t get the text area to update
index.js.erb