Reputation: 242
Can anyone tell me what is the difference between these two? I seem to get the same result
<%= form_for (@message) do |f| %>
vs
<%= form_for Message.new, remote: true do |f| %>
Upvotes: 0
Views: 50
Reputation: 29094
remote: true
is used to make the form submit happen via AJAX.
More info about this is available in Rails Guides (Courtesy Arup)
The other difference lies in the object @message
. If it was initialized using existing data from the database, the form generated will come pre-filled
eg, If in the controller code is
@message = Message.new
Then the output of the two forms will be identical, but if the controller code is
@message = Message.find(params[:id])
then the form will be filled with values of @message
Upvotes: 2