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
 
         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论