开发者

Rails: using a variable for creating a record

开发者 https://www.devze.com 2023-03-26 06:49 出处:网络
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.

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


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
0

精彩评论

暂无评论...
验证码 换一张
取 消