开发者

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


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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜