views:

18

answers:

1

Here's is my permissions controller for DEF UPDATE:

def update

  @permission = Permission.where(:user_id=> params[:permission][:user_id] ).where(:project_id=> params[:permission][:project_id]).first

  respond_to do |format|
    if @permission.update_attributes( params[:role_id] )
        format.js  { render :layout => false }
    else
        format.js  { render :layout => false }
    end
  end

Form Post Header utf8:✓ _method:put authenticity_token:17rvYJmq7167 ktDBXZgDnopH3QY/Tb5a3K0jtcTjrU= permission%5Brole_id%5D:3 permission%5Buser_id%5D:11 permission%5Bproject_id%5D:3

No errors here, but the role_id is not being updated? Ideas? Thanks

+2  A: 

You're passing params[:role_id] as the parameter to update_attributes, but this isn't set according to the post data you included.

I think what you probably mean is this:

if @permission.update_attribute(:role_id, params[:permission][:role_id])
    ...
end
Tim Fountain
Strange. that errors: "NoMethodError (undefined method `eq' for nil:NilClass): app/controllers/permissions_controller.rb:46:in `update' app/controllers/permissions_controller.rb:45:in `update'"
AnApprentice
Full debugger log: "(rdb:31) @permission#<Permission project_id: 3, role_id: 2, user_id: 11>(rdb:31) params[:permission][:role_id]"1"(rdb:31) @permission.update_attribute(:role_id, params[:permission][:role_id])NoMethodError Exception: undefined method `eq' for nil:NilClass(rdb:31) "
AnApprentice
Which line is 46? Note that I changed update_attributes to update_attribute in my code sample.
Tim Fountain
@Tim, thanks it's update_attribute not attributes in the code now. " 46 47 respond_to do |format| 48 if @permission.update_attribute(:role_id, params[:permission][:role_id]) 49 format.js { render :layout => false }"
AnApprentice
is it bec this table has no ID? (rdb:31) @permission.idnil
AnApprentice
Ah, yes, that'd do it. Simplest solution might be to destroy the record and create a new one.
Tim Fountain
ahh shoot. really? Should I add an ID to this table? even though it's a Y-Model, for Projects, Roles, Users?
AnApprentice
Yup, id would make things easier too. Normally for lookup tables you can just use HABTM, but as soon as you need extra fields you need a model for it. See http://blog.hasmanythrough.com/2006/4/20/many-to-many-dance-off for a detailed write up.
Tim Fountain