views:

43

answers:

1

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?

+2  A: 

user_id is further down the params hash. Try:

params[:permission][:user_id]
DGM
That did it. Thank you! Bonus points for helping me understand why that is the case? Why is it down the params hash? thxs
AnApprentice
f.hidden_field is automatically tied to the permission object. If user_id does not belong to the permission object, then don't use the f object, just use a plain hidden_field helper.
DGM
BTW, use your log file, it told us this. Notice that user_id is inside the brackets that "permission" points to.
DGM