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) %> |
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 Issues · rails/jquery-ujs · GitHub.
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?