Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3932480
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T23:27:49+00:00 2026-05-19T23:27:49+00:00

I am using Rails 3.0.3 with jQuery ujs. I want to send a form

  • 0

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 %>
<div class="dialog">
<table>
<tbody>
<tr class="prop">
<td valign="top" class="name">
 <%= label_tag(:location_start, "Location Start:") %>
</td>
<td valign="top">
<%= text_field_tag(:location_start) %>
</td>
...
</tbody>
</table>
</div>
<div class="buttons">
<span class="button"><%= submit_tag("Search") %></span>
</div>
<% 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("<h1>Headline</h1>");

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T23:27:49+00:00Added an answer on May 19, 2026 at 11:27 pm

    Solved the problem by replacing <%= form_tag :remote => true, :controller => "mains", :action => "search", :format => :js do %> with <%= form_tag( {:controller => "mains", :action => "search"}, :remote => true ) do %> and updating to the newest version of jQuery ujs…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using jQuery with rails and have the following piece of code $('#related').html(<%= render
I have started using jQuery and rails. I have made a simple form that
I am using jquery-rails-autocomplete and want to have autocomplete on more than one column.
I am confused by how ajax:before works when using rails/jquery-ujs. Does it wait for
I have a simple search form that looks something like: app/views/search/index.html.erb <%= form_for @search,
I have just started considering using the HTML 5 api for a Rails/JQuery project,
I am using Rails 3, Jquery-UJS and Jquery. I have a working setup of
I'm using Rails 2.3.8 and have a jQuery AJAX form using posted using: jQuery.fn.submitWithAjax
Using Ruby 1.8.7-p358, Rails 3.0.12, gem responder, gem simple-form; jquery_ujs.js I have a form
I am using Rails and jQuery, making an ajax call initiated by clicking a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.