I came to my first remote form in a new rails 3 application and I can not get it to send remotely: it continues to send as html. I did it fine in other applications with rails 3, so I think this is just what I forgot.
Here is my form in my html.erb file:
<%= form_for Assignment.new, :remote => true do |f| %> <%= hidden_field_tag "assignment[task_id]", @task.id %> <%= hidden_field_tag "assignment[person_id]", person.id %> <%= submit_tag "Add to task" %> <% end %>
And here is how it is displayed on the page. I have included links to javascript files as I have a feeling that the problem is that js is not configured properly.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8" /> <script src="/javascripts/jquery.js?1306857355" type="text/javascript"></script> <script src="/javascripts/person.js?1306857355" type="text/javascript"></script> <script src="/javascripts/jquery-ui-1.8.11.custom.min.js?1306857355" type="text/javascript"></script> <script src="/javascripts/jquery_ujs.js?1306857355" type="text/javascript"></script> <script src="/javascripts/jquery.ui.datepicker.js?1306857355" type="text/javascript"></script> <script src="/javascripts/jquery.colorbox-min.js?1306857355" type="text/javascript"></script> <script src="/javascripts/jquery.tipTip.minified.js?1306857355" type="text/javascript"></script> <script src="/javascripts/application.js?1306857355" type="text/javascript"></script> <meta name="csrf-param" content="authenticity_token"/> <meta name="csrf-token" content="ErI0bMA1E0JAXwvyVMistPsWc4fg2dG5tDPOgeur358="/> </head> <body class="tasks"> <form accept-charset="UTF-8" action="/assignments" class="new_assignment" data-remote="true" id="new_assignment" method="post"> <div style="margin:0;padding:0;display:inline"> <input name="utf8" type="hidden" value="✓" /> <input name="authenticity_token" type="hidden" value="ErI0bMA1E0JAXwvyVMistPsWc4fg2dG5tDPOgeur358=" /> </div> <input id="assignment_task_id" name="assignment[task_id]" type="hidden" value="2" /> <input id="assignment_person_id" name="assignment[person_id]" type="hidden" value="1" /> <input name="commit" type="submit" value="Add to task" /> </form> </body> </html>
It appears to be configured correctly. But, when I submit, I get this through my journal:
Started POST "/tasks/2" for 127.0.0.1 at 2011-06-08 15:56:42 +0100 Processing by TasksController#update as HTML Parameters: {"utf8"=>"✓", "authenticity_token"=>"ErI0bMA1E0JAXwvyVMistPsWc4fg2dG5tDPOgeur358=", "assignment"=>{"task_id"=>"2", "person_id"=>"1"}, "commit"=>"Add to task", "id"=>"2"}
As I said, I think that I just missed what I needed to do to properly correct it. Here is also my Gemfile, if necessary:
source 'http://rubygems.org' gem "rake", "0.8.7" gem 'rails', '3.0.7' gem 'haml' gem 'heroku' gem "heroku_backup_task" gem 'authlogic', '3.0.2' gem 'rails3-generators' gem 'txtlocal', :git => 'git://github.com/epigenesys/txtlocal.git' gem 'chronic' gem 'sqlite3-ruby', :require => 'sqlite3' gem 'bcrypt-ruby' gem 'taps'
Can anyone see what is missing?
thanks max
EDIT is a stupid mistake on my part: a partial one containing a remote form is called from another non-dual form that caused the same action. Thus, the external form was triggered by the submit button, and not the internal remote. Doh. Thank you for reading.