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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:24:12+00:00 2026-05-27T18:24:12+00:00

In Rails 3.1, I want to create an embedded object by using a create

  • 0

In Rails 3.1, I want to create an embedded object by using a create method that accepts parameter data, but I am wondering if there is a more elegant way to do this than the case method below:

def method_call(obj,data)
  case obj
  when 'a' then User.create_a(data)
  when 'b' then User.create_b(data)
  when 'c' then User.create_c(data)
  end
end

I would really like to do something like the following, but the this causes an error because of the data that I pass:

def method_call(obj,data)
  User.send("create_#{obj}")(data)
end

Any suggestions? Thanks in advance.

  • 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-27T18:24:13+00:00Added an answer on May 27, 2026 at 6:24 pm

    The send method takes the same parameters given to the method being called:

    User.send("create_#{obj}", data)
    

    Whether or not this is the most elegant solution depends: I’d leave the decision-making process up to the User class, which could happen in a variety of ways (e.g., a send like this, a hash of Procs, etc.) A factory service is another alternative.

    User.create(how, data) # "how" is a, b, c
    

    Wherever it lives, make it obvious–this makes it easy to extend, fix, and reason about.

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

Sidebar

Related Questions

I am using Rails 3. I just want to create a simple javascript object
I want to create a Rails (2.1 and 2.2) model with ActiveRecord validations, but
I am using Ruby on Rails. I want to create a filter field on
I have a Rails 3 App using devise. I want to create a User/Profile
I want to create person objects in my rails app using a jquery ajax
I want to create an open source banner/advertising management app using Rails. The app
I have a Rails 3.1 app that I want to create an API for.
New to Rails... here goes: If I want my 'create' method to respond differently
I'm using jquery-mobile with Ruby On Rails. I want to create a button link
I want to create a public live chat application using rails 3. I found

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.