jakobk
jakobk

Reputation: 1132

Rails: using a variable for creating a record

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

Upvotes: 1

Views: 83

Answers (1)

Michelle Tilley
Michelle Tilley

Reputation: 159105

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

Upvotes: 2

Related Questions