Rails 3.1将参数从View传递给控制器

时间:2012-03-21 18:56:29

标签: ruby-on-rails ruby-on-rails-3

我正在使用Rails 3.1并且我的视图返回控制器这个参数(我在Web服务器日志上检查过它):

"warehouse"=>{"asset"=>"turiturira", "serial"=>"caricarira", "project_id"=>"1", "hardware"=>{"brand_id"=>"21"}, "hardware_id"=>"60", "state_id"=>"4", "position_id"=>"1", "logicalwarehouse_id"=>"3", "extra_id"=>"3"}, "bulk_warehouse_serial270"=>"t", "bulk_warehouse_asset270"=>"test", "enable_record270"=>"1", "bulk_warehouse_serial271"=>"uela2", "bulk_warehouse_asset271"=>"bela2", "enable_record271"=>"1"}

现在我应该使用这个参数。我知道如果我需要所有仓库参数,我可以做一些事情,如:

@warehouse = Warehouse.new(params[:warehouse])

但如果我需要“仓库”内的单个参数,我该怎么办?假设我想将@serial变量设置为“bulk_warehouse_serial270”值(“test”);我应该做些什么,如:

@serial = params(:warehouse[:bulk_warehouse_serial270]) 

或代之以:

@serial = params(:warehouse)params(:bulk_warehouse_serial270)

任何人都可以帮助我?

1 个答案:

答案 0 :(得分:5)

那是params[:warehouse][:asset]