Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/56.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/60.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql Rails:使用变量创建记录_Mysql_Ruby On Rails_Ruby_Variables_Controller - Fatal编程技术网

Mysql Rails:使用变量创建记录

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

我有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
  @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。创建(…);-)