简体   繁体   中英

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

@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?

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"}

User Load (0.3ms) SELECT "users".* FROM "users" WHERE ("users"."id" = 1) LIMIT 1

Permission Load (0.1ms) SELECT "permissions".* FROM "permissions" WHERE ("permissions"."user_id" IS NULL) LIMIT 1

see - user_id is NULL?

user_id is further down the params hash. Try:

params[:permission][:user_id]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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