2014-10-29 44 views
0
**Request 
Parameters:** 

{"utf8"=>"✓", 
"_method"=>"patch", 
"authenticity_token"=>"rXhIA6/LAP8Kla9kMExq16bpr51WeFyPo0vDi9sE86c=", 
"id"=>"2", 
"user"=>{"role_id"=>"3"}, 
"commit"=>"Change Role"} 

如何從控制器中的「role_id」獲取參數3? 我試圖如何在rails中處理參數?

@role = (params[:user]) 

,但我只得到

{"role_id"=>"2"} 
+0

嘗試'@Role =(PARAMS [:用戶] [:ROLE_ID])' – anusha 2014-10-29 09:35:19

回答

0

試試這個:

@role = params[:user][:role_id] 

給你結果@role = 3