In my _form.html.erb file, I have;
<%= form_for(@document) do |f| %>
<% end %>
When I add
<%= form_for(@document), :remote => true do |f| %>
<% end %>
I get an error. I want to add ajax to this form so the user can submit it, it'll appear with a notice saving "saved" and then the user can carry on writing in the textarea within the form.
The error says:
SyntaxError in Documents#edit
Showing /app/views/documents/_form.html.erb where line #1 raised:
<%= form_for(@document), :remote => true do |f| %>
It's saying that line 1 (above) is a syntax error.
How can I add remote true to the form_for so I can add Ajax?
So out of the two answers, I have;
<%= form_for(@document, :remote => true) do |f| %>
and
<%= form_for @document, :remote => true do |f| %>
They both work but is one better than the other or do they end up doing the same thing?
You've inserted the :remote = true
right AFTER the parameter list. Just leave off the parenthesis.
<%= form_for @document, :remote => true do |f| %>
<%= form_for(@document, :remote => true) do |f| %>
...
<% end %>
reefer this : http://apidock.com/rails/ActionView/Helpers/FormHelper/form_for
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With