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 7406293
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:32:09+00:00 2026-05-29T05:32:09+00:00

I have two different layouts in my app, one for javascript (AJAX) requests and

  • 0

I have two different layouts in my app, one for javascript (AJAX) requests and one for regular requests.

# application.html.haml for non-js requests (abbreviated)
!!!
%html
  %head
  %body
    = yield

# and application.js.coffee for js requests
App.modal """<%= yield %>""" # creates a javascript modal

Any link with :remote => true should in theory use the javascript layout. This DOES work on certain occasions, but does not work on others.

It works for this link:

%li= link_to "Login", new_user_session_path, remote: true

# log output:
Started GET "/users/sign_in?&authenticity_token=KwyFmzGgR7Rdx3dudJDvw8b5rngvVDrwfTpYLPIPjEI=" for 127.0.0.1 at 2012-01-27 03:29:41 -0500
Processing by Devise::SessionsController#new as JS
  Parameters: {"authenticity_token"=>"KwyFmzGgR7Rdx3dudJDvw8b5rngvVDrwfTpYLPIPjEI="}
  Rendered devise/shared/_links.erb (0.9ms)
  Rendered devise/sessions/new.html.haml within layouts/application (6.3ms)
Completed 200 OK in 167ms (Views: 165.9ms | ActiveRecord: 0.0ms)

# output in the javascript console:
XHR finished loading: "http://localhost:3000/users/sign_in?&authenticity_token=KwyFmzGgR7Rdx3dudJDvw8b5rngvVDrwfTpYLPIPjEI=".

But does not work for this one:

%li= link_to "Account", edit_user_registration_path, remote: true

# log output:
Started GET "/users/edit?&authenticity_token=KwyFmzGgR7Rdx3dudJDvw8b5rngvVDrwfTpYLPIPjEI=" for 127.0.0.1 at 2012-01-27 03:31:24 -0500
Processing by Devise::RegistrationsController#edit as JS
  Parameters: {"authenticity_token"=>"KwyFmzGgR7Rdx3dudJDvw8b5rngvVDrwfTpYLPIPjEI="}
  User Load (0.3ms)  SELECT "users".* FROM "users" WHERE "users"."id" = 1 LIMIT 1
  MobilePhone Load (0.3ms)  SELECT "mobile_phones".* FROM "mobile_phones" WHERE "mobile_phones"."user_id" = 1 LIMIT 1
  Rendered devise/registrations/edit.html.haml within layouts/application (6.7ms)
Completed 200 OK in 157ms (Views: 154.4ms | ActiveRecord: 0.6ms)

# output in the javascript console:
XHR finished loading: "http://localhost:3000/users/edit?&authenticity_token=KwyFmzGgR7Rdx3dudJDvw8b5rngvVDrwfTpYLPIPjEI=".

After some simple debugging, I realized that the second request is hitting application.html.haml (wrong!), while the first one is hitting application.js.coffee (correct!). Both are being processed successfully by ajax.

I am a bit stumped here. I am hoping that I am making a simple mistake that somebody will be able to point out!

Thanks!

P.S. I am running rails 3.2.1 (and previously tried on 3.1.3 with same issue)

EDIT: Not sure if it makes a difference, but I am using the mootools-rails driver: https://github.com/kevinvaldek/mootools-ujs/blob/master/Source/rails.js. The accepts header is being set properly to “text/javascript”.

  • 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-29T05:32:09+00:00Added an answer on May 29, 2026 at 5:32 am

    This is what I had to do to get this to work: (and has nothing to do with the javascript library)

    # whatever_controller.rb
    def index
      respond_to do |format|
        format.js   # renders index.html.haml inside application.js.haml layout
        format.html # renders index.html.haml inside application.html.haml layout
      end
    end
    

    Alternatively, you could just rename the template for the action to index.js.haml instead of index.html.haml, which would work for ajax requests without using respond_to. However, that would mean that search engines and browsers without javascript enabled would not be able to access the page.

    Another method that would also work is to use respond_with:

    # application_controller.rb
    respond_to :html, :js
    
    # whatever_controller.rb
    def index
      respond_with # will render the appropriate layout
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a way to have two different Java code for one Android app?
I have two different ways of displaying items in a WPF application. The first
I have two different styles for my window: Regular - window has title bar
I have two different modules that need access to a single file (One will
I have two different grid controls on the same form. They share the same
I have two different-sized monitors, connected together using (I believe) TwinView. I tried System.out.println(Toolkit.getDefaultToolkit().getScreenSize());
I have two different tables, lead and click. I would like to query MySQL
We have two different ldap providers in two different physical office locations. When I
I have two different tables from which I need to pull data blogs which
I have two different applications and I am using GroupLab Networking to communicate between

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.