Answer the question
In order to leave comments, you need to log in
Is the form submitted twice?
Rails 3.1.2, for some reason forms are submitted twice instead of once...
# _form.html.erb<br>
<%= form_for @message, :remote => true do |f| %><br>
<div><br>
<%= f.hidden_field :user_id %><br>
</div><br>
<%= f.error_messages %><br>
<div><br>
<%= f.text_area :content %><br>
</div><br>
<div><br>
<%= f.submit(@message.new_record? ? "Post" : "Update") %><br>
</div><br>
<% end %><br>
<br>
# messages_controller.rb<br>
...<br>
def update<br>
@message = Message.find(params[:id])<br>
if @message.update_attributes(params[:message])<br>
respond_to do |format|<br>
format.html { redirect_to @message, :notice => "Successfully updated message." }<br>
format.json { render :json => { :response => :ok, :id => @message.id }.to_json,<br>
:status => :ok }<br>
format.js { render :js => "alert('ok!');" }<br>
end<br>
else<br>
format.html { render edit_message_path }<br>
format.json { render :json => { :response => :error }.to_json,<br>
:status => :error }<br>
format.js { render :js => "alert('fail!');" }<br>
end<br>
end<br>
...<br>
Answer the question
In order to leave comments, you need to log in
Maybe jquery or jquery_ujs is loaded 2 times, look through firebug or chrome dev tools.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question