I am a bit confused as to why I am getting an error updating an
object.
This is the ERROR: Couldn’t find User without an ID
In my development.log file I noticed the following when trying to
initiate the update:
Processing AdminController#update_user (for 127.0.0.1 at 2007-02-16
13:20:23) [POST]
Session ID: 2a5030c37fa9726e6e29d7a024ce97ab
Parameters: {“user”=>{“name”=>“joseph”,
“hashed_password”=>“3708cf23bf5bcd14a2383a4fb24c4af1fb4fb352”,
“user_type”=>“nelnet”, “user_role”=>“user”}, “commit”=>" Update User
", “action”=>“update_user”, “id”=>“11”, “controller”=>“admin”}
[4;36;1mUser Load (0.000761) [0m [0;1mSELECT * FROM users WHERE
(users.id = ‘11’) LIMIT 1 [0m
[4;35;1mUser Columns (0.002650) [0m [0mSHOW FIELDS FROM
users [0m
[4;36;1mSQL (0.001330) [0m [0;1mBEGIN [0m
[4;35;1mUser Load (0.000497) [0m [0mSELECT * FROM users WHERE
(users.name = ‘joseph’ AND users.id <> 11) LIMIT 1 [0m
[4;36;1mSQL (0.000096) [0m [0;1mCOMMIT [0m
Redirected to http://localhost:3000/admin/edit_user
Completed in 0.01380 (72 reqs/sec) | DB: 0.00533 (38%) | 302 Found
[http://localhost/admin/update_user/11]
What I find most confusing is this line:
SELECT * FROM users WHERE (users.name = ‘joseph’ AND users.id <> 11)
LIMIT 1
I am confused why Rails would make this call with update_attributes.
I am lost.
Any help would be greatly appreciated!
Thanks,
-E
Here is snippets of my Admin controller code that is in question:
def edit_user
@user = User.find(params[:id])
end
def update_user
@user = User.find(params[:id])
if @user.update_attributes(params[:user])
flash[:notice] = "User #{@userUpdate.name} updated
successfully"
redirect_to(:action =>:list_users)
else
flash[:notice] = “Unable to process change, please try again”
redirect_to(:action =>:edit_user)
end
end
Here is the edit_user.rhtml file:
Update User
<%= start_form_tag :action => ‘update_user’, :id => @user %>
<%= render :partial => ‘form’ %>
<%= submit_tag " Update User " %>
<%= end_form_tag %>
<%= link_to ‘Back’, :action => ‘list_users’ %>
Here is the _form.rhtml file:
<%= error_messages_for ‘user’ %>
Username: | <%= text_field("user","name") %> | |
Password: | <%= password_field("user","hashed_password") %> | |
User Type: | <%= select("user","user_type", %w{nelnet wsu}) %> | |
User Role: | <%= select("user","user_role", %w{user super admin}) %> |
Any help would be great