简体   繁体   English

Rails 3-在控制器更新中使用表单参数吗?

[英]Rails 3 - Using form Params in a controller's Update?

I have the following form: 我有以下表格:

<%=form_for [:project, @permission], :url => { :action => "update" } do |f| %>
 <% roles = Role.all %>
 Role: <%= f.collection_select :role_id, roles, :id, :name, :prompt => true %> 

 <%=f.submit "Send Request" %>
 <%=f.hidden_field :user_id %>
<% end %>

In my controller I have: 在我的控制器中我有:

def update def更新

@permission = Permission.find_by_user_id(params[:user_id])
.
.
.

end 结束

** What I want to do is update the role_id,,,, so I need the above to find the permission record... Problem is,,, params[:user_id] is coming back null? **我想做的是更新role_id,因此,我需要上面的内容来找到权限记录...问题是,params [:user_id]返回null?

Am I missing something? 我想念什么吗? thanks 谢谢

Update 更新

Here is the error and request params, which show the vars are there? 这是错误和请求参数,表明存在变量吗?

Started POST "/projects/3/permissions/useronproject" for 127.0.0.1 at Thu Oct 14 12:17:12 -0700 2010 Processing by PermissionsController#update as HTML Parameters: {"commit"=>"Send Request", "authenticity_token"=>"KJ2C20MzTJ8VQV0NiNzOr357QKV5hWjeuazOBcS5iPU=", "utf8"=>"✓", "id"=>"useronproject", "permission"=>{"role_id"=>"1", "user_id"=>"11"}, "project_id"=>"3"} 在2010年10月14日星期四,127.0.0.1开始POST“ / projects / 3 / permissions / useronproject”,由PermissionsController#update作为HTML参数进行处理:{“ commit” =>“ Send Request”,“ authenticity_token “ =>” KJ2C20MzTJ8VQV0NiNzOr357QKV5hWjeuazOBcS5iPU =“,” utf8“ =>”✓“,” id“ =>” useronproject“,”权限“ => {” role_id“ =>” 1“,” user_id“ =>” 11“} ,“ project_id” =>“ 3”}

User Load (0.3ms) SELECT "users".* FROM "users" WHERE ("users"."id" = 1) LIMIT 1 用户负载(0.3毫秒)选择“用户”。*从“用户”位置(“用户”。“ id” = 1)限制1

Permission Load (0.1ms) SELECT "permissions".* FROM "permissions" WHERE ("permissions"."user_id" IS NULL) LIMIT 1 权限负载(0.1ms)在“ permissions”中选择“ permissions”。*(“ permissions”。“ user_id”为NULL)LIMIT 1

see - user_id is NULL? 看到-user_id为NULL?

user_id is further down the params hash. user_id在params哈希值的下方。 Try: 尝试:

params[:permission][:user_id]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM