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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:52:09+00:00 2026-05-23T09:52:09+00:00

I have an odd situation, but here it is: # a HAML file :javascript

  • 0

I have an odd situation, but here it is:

# a HAML file
:javascript
  #{ if session[:view].blank?
        "$.ajax({
            url: 'url_for params.merge(:action => 'index')',
            dataType: 'script'})"
    else
        "$.ajax({
            url: 'url_for companies_url',
            dataType: 'script'})"
    end }

So this is basically nesting javascript inside ruby, inside javascript, inside HAML. It doesn’t work because I’ve got improper nesting of quotes.

  1. I imagine there’s a better way to do this. Any thoughts?
  2. The ajax happening above renders some partials into the current view and changes the session variable. How can I update this javascript so it behaves correctly given the new session[:view]?
  • 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-23T09:52:09+00:00Added an answer on May 23, 2026 at 9:52 am

    Use ERB and a helper method. It’s a lot cleaner:

    # foo_helper.rb (or whichever helper is applicable for this view)
    module FooHelper
      def url_for_ajax_call
        if session[:view].blank?
          url_for(params.merge(:action => 'index'))
        else
          # url_for(companies_url) is redundant
          companies_url
        end
      end
    end
    
    # view.js.erb
    $.ajax({ url: <%= url_for_ajax_call %>, dataType: 'script' })
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a bit of an odd situation. Here's what's happening. So, we have
This is a pretty odd situation I have here. I have used a piece
I have what seems like an odd situation here. I'm launching dialogs from a
I have run into an odd situation. I'm writing a JavaScript bookmarklet that will
I have an odd situation in which I need to modify the position of
Ok, well I have sorta of an odd situation. I have a two applications.
We have a very odd problem here with SVN. Let me first explain the
I have an odd question that I have always thought about, but could never
OK, so this may be an odd situation but please bear with me. I
I have recently came upon odd situation; HTML formatted text in my Swing components

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.