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?
Update
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?
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?
Update
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?
Share Improve this question edited Jun 20, 2020 at 9:12 CommunityBot 11 silver badge asked Dec 15, 2012 at 14:21 user1658756user1658756 1,0245 gold badges13 silver badges27 bronze badges 1- The ONLY difference is aesthetic. Omitting the parentheses is a matter of style preference. – Jesse the Game Commented Nov 13, 2013 at 13:38
3 Answers
Reset to default 16You'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
Also with namespace you can use
<%= form_for [:namespace, @document], html: { help: :block }, remote: true do |f| %>
...
<% end %>