Can't get a FORM to submit remotely in Rails 3.0.3?

Hi,

I am using Rails 3.0.3 with jQuery ujs.

I want to send a form remotely. The view template
mains/index.html.erb containing the form looks as follows:


<%= form_tag :remote => true, :controller => “mains”, :action =>
“search”, :format => :js do %>

...
<%= label_tag(:location_start, "Location Start:") %> <%= text_field_tag(:location_start) %>
<%= submit_tag("Search") %>
<% end %> ...

The controller mains_controller.rb looks as follows (removed
unnecessary stuff):

class MainsController < ApplicationController

def index
respond_to do |format|
format.html # index.html.erb
end
end

def search
respond_to do |format|
format.js { render :template => ‘mains/search.js.erb’}
end
end

end

The view template mains/search.js.erb has the following content:

$(’#search’).html(“

Headline

”);

I am using search.js.erb instead of search.js.rjs due to instructions in
chapter “26.4 Write Less and Do More with JQuery” in Agile Web
Development with Rails (4h edition). I also added :format => :js due
to https://github.com/rails/jquery-ujs/issues/closed/#issue/52.

When I call http://0.0.0.0:3000/mains/index and submit the form,
it’s actually not submitted remotely, but the browser loads
http://0.0.0.0:3000/mains/search.js?remote=true instead. The browser
outputs $('#search').html("<h1>Headline</h1>");, instead of executing
the JavaScript by replacing div#search with <h1>Headline</h1> given.

I tried to find a solution but wasen’t successful so far… Could anyone
help?

i think changing the form_tag to

form_tag {:controller => ‘mains’, :action => ‘search’, :format => :js},
:remote => true do

should work. The brackets are there to separate the url_for options with
the
html_options.

On Thu, Feb 3, 2011 at 5:10 PM, Matthias S. [email protected]
wrote:

format.js { render :template => ‘mains/search.js.erb’}
chapter “26.4 Write Less and Do More with JQuery” in Agile Web
help?
.
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs