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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:57:25+00:00 2026-06-17T11:57:25+00:00

This is a Ruby question though I use it in a Rails context. I

  • 0

This is a Ruby question though I use it in a Rails context.

I need to call a method where I use string variables to assign values to its keys (parameter names).

For instance I got :

MyRailsModelClass.where(key_of_my_method: my_value)

I want to make this more dynamic.
I can create a MyRailsModelClass like this “my_rails_model_class”.classify

I need to make key_of_my_method more dynamic and replace it with a variable.
I’m thinking about something like :

"my_rails_model_class".classify.where(my_key.to_sym => my_value)

Does anybody has a clue ?
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-06-17T11:57:27+00:00Added an answer on June 17, 2026 at 11:57 am

    Actually, classify method is not enough. You need to constantize before to apply any class method.

    I solved it this way (because it is much more efficient; while classify do call many more methods : camelize(singularize(table_name.to_s.sub() ) :

    "my_rails_model_class".camelize.constantize.where("my_key".to_sym == my_value).first
    

    but you could do it the longuer way :

    "my_rails_model_class".classify.constantize.where("my_key".to_sym == my_value).first
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Take the following method (written in Ruby but this question could be applied to
This is more a general question but my particular case involves a ruby/rails app
This is related to a question I asked here: Thread Locking in Ruby (use
I am using Ruby on Rails, but I think this question could be applied
Im just messing around with Ruby on Rails and HTML. This question isn't about
This question is a follow up to this previous question: Ruby on Rails: Custom
This question is similar to Why are methods in Ruby documentation preceded by a
I've just started learning ruby, so this question is simple. I created @subject in
Context: I am trying to practice BDD in a Ruby on Rails environment using
I am only looking for answers from senior/more experienced Ruby/Rails developers on this one,

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.