1

I have 4 different groups of data that I want to: create, update, delete

I want to use one action for each function, using a variable, but can't get it to work.

For example:

def create

@type = params['type']   # use an outside ajax request to decide type
@type.create(:title => 'new title')  # create a new table using that type

end

1 Answer 1

2

Have you tried constantize?

def create
  @type = params['type'].constantize   # use an outside ajax request to decide type
  @type.create(:title => 'new title')  # create a new table using that type
end
Sign up to request clarification or add additional context in comments.

1 Comment

@jakobk, remember to use a whitelist, you don't want a GlobalThermonuclearWar.create(...) ;-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.