Mysql Rails:使用变量创建记录
我有4组不同的数据,我想: 创造,, 更新, 删除 我想为每个函数使用一个操作,使用一个变量,但无法使其工作 例如:Mysql Rails:使用变量创建记录,mysql,ruby-on-rails,ruby,variables,controller,Mysql,Ruby On Rails,Ruby,Variables,Controller,我有4组不同的数据,我想: 创造,, 更新, 删除 我想为每个函数使用一个操作,使用一个变量,但无法使其工作 例如: 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 您是否尝试过将恒定化 def create @t
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
您是否尝试过将
恒定化
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
@jakobk,记住使用白名单,你不需要GlobalThermonClearWar。创建(…);-)