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

  • Home
  • SEARCH
  • 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 3615602
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T22:23:39+00:00 2026-05-18T22:23:39+00:00

I’m working to setup an AJAX action in rails 3 with the following code.

  • 0

I’m working to setup an AJAX action in rails 3 with the following code. The AJAX part of the code seems to work, but it does not request the correct file and my respond_to serves it the regular HTML.

The routing information:

resources :zones do
  resources :records
end

controller:

def new
  @zone = Zone.new
  respond_to do |format|
    format.html
    format.js
  end
end

Link in view (haml):

= link_to 'Add a zone →', new_zone_path, :remote=>true

Generated HTML from link_to (also notice the failed rendering of the html entity…but thats another issue):

<a href="/zones/new" data-remote="true">Add a zone &amp;#8594;</a> 

For kicks, a directory listing of the view/zones. I’m not sure I am doing this quite right,
so I have both new.js.rjs and new.rjs. They both have the same content, but are never picked up by the action.

|   `~zones/
|     |-_form.html.haml
|     |-_record.html.haml
|     |-edit.html.haml
|     |-index.html.haml
|     |-new.html.haml
|     |-new.js.rjs
|     |-new.rjs
|     `-show.html.haml

Lastly, the server log from when I click the link:

Started GET "/zones/new" for 127.0.0.1 at Wed Dec 29 00:04:03 -0700 2010
  Processing by ZonesController#new as */*
  User Load (0.4ms)  SELECT "users".* FROM "users" WHERE ("users"."id" = 1) LIMIT 1
Rendered zones/_form.html.haml (22.1ms)
Rendered zones/new.html.haml within layouts/application (34.9ms)
Completed 200 OK in 80ms (Views: 42.0ms | ActiveRecord: 0.4ms)

As you can see, it is rendering the .html file for the request. Now, for testing, I hit the page http://localhost:3000/zones/new.js directly. And it serves up new.js.rjs. Also, the javascript remote call is working. Firebug shows the request and response, but its requesting the wrong page.

Also for testing I did this:

= link_to "Add a zone", '/zones/new.js', :remote=>true

Which works fine (rjs is downloaded and executed and works correctly) for the javascript but it doesn’t have the nice failover for javascript-disabled systems.

For what it is worth I am using jquery.

I feel like I am missing something in the routing or the link syntax but all the examples I can find online and in the documentation seem to show exactly what I am doing. Whats the catch?

Thanks.

  • 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-18T22:23:39+00:00Added an answer on May 18, 2026 at 10:23 pm

    You need to explicitly tell Rails that you want the js format:

    = link_to 'Add a zone &#8594;', new_zone_path(:format => :js), :remote=>true
    

    As a way of explanation: You have to specify the .js extension because Rails doesn’t discriminate. In many cases, you might want to fetch html or json with Ajax–not just javascript. Rails will let you fetch whatever content in whatever format, which is why you have to specify it.

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

Sidebar

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
I want to count how many characters a certain string has in PHP, but
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I want use html5's new tag to play a wav file (currently only supported
this is what i have right now Drawing an RSS feed into the php,

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.