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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:37:29+00:00 2026-05-28T00:37:29+00:00

Sorry, I’m not even sure how to ask this question.. so if you could

  • 0

Sorry, I’m not even sure how to ask this question.. so if you could suggest around that as well, it would be appreciated.

# A. WORKS, but "stockroom" is hardcoded
render partial: association.to_s.singularize + '',
  locals: {stockroom: new_object}

# B. WORKS, but uses old syntax
render partial: association.to_s.singularize + '',
  locals: {association.to_s.singularize.to_sym => new_object}

# C. does NOT work
render partial: association.to_s.singularize + '',
  locals: {association.to_s.singularize.to_sym: new_object}

# D. does NOT work
ass = association.to_s.singularize.to_sym
logger.debug "--- ass: #{ass.inspect} (#{ass.class})"
  # => --- ass: :stockroom (Symbol)
render partial: association.to_s.singularize + '', locals: {ass: new_object}

Not that the old syntax is a bad thing, I’m just wondering if there’s a way to do this using the new syntax (even via an intermediary (i.e. ass)).

  • 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-28T00:37:29+00:00Added an answer on May 28, 2026 at 12:37 am

    The JavaScript style syntax is not really the new syntax, it is just an alternate syntax in 1.9 that can be used for some symbol literals within a Hash literal.

    You can’t use the trailing-colon style with all symbols, try these and you’ll see:

    { :$set => 11 }                       # Valid
    { $set: 11 }                          # Invalid
    { :'where.is.pancakes.house?' => 23 } # Valid
    { 'where.is.pancakes.house?': 23 }    # Invalid
    

    Similarly, if you have a symbol that isn’t a symbol literal:

    s = o.to_sym; { s => 42 }
    { o.to_sym => 42 }
    

    then you have to use the fat arrow syntax in your Hashes. The same applies if you have a key that isn’t a symbol:

    a = %w{where is pancakes house?}
    h = { a => 11 }
    g = { a: 11 } # Also works but produces a completely different result!
    

    In summary, the trailing-colon converts some literal values (I think anything that matches /\A[a-z_]\w*\z/i but I’m not certain) that precede it to symbols when used inside a Hash literal. Basically, the JavaScript style is useless in all but the most trivial cases; but the trivial cases do happen to be the most common.

    The only way I can think of to use the JavaScript style with a non-literal symbol would be an abomination like this:

    ass = association.to_s.singularize.to_sym
    h   = eval "{ #{ass}: 'pancakes' }"
    

    and if you ever put something like that in real code then may the gods have mercy on your soul.

    Also, keep in mind that you have to use the leading-colon form of the symbol when you want to access your hash:

    h[:pancakes] # Valid
    h[pancakes:] # Invalid
    

    so the JavaScript style is of limited utility.

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

Sidebar

Related Questions

Sorry for this not being a real question, but Sometime back i remember seeing
Sorry for the second newbie question, I'm a developer not a sysadmin so this
Sorry I could not find this. $('div#loader').slideDown(fast).delay(1.5); Does not word as expected, I want
sorry for lamer question, but I really could not found subject. I have a
Sorry, I'm new to SVN and I looked around a little for this. How
Sorry if this sounds like a really stupid question, but I need to make
Sorry if this is a noob question, but All my code is error-free and
Sorry for puting this silly question: I am reading the book Using R for
Sorry about this newbie question. Is there a way to execute multiple sentences at
Sorry if this is a simple question, but I've only recently started learn coding

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.