Witajcie.
Nigdy nie przypuszczałem, że po załapaniu podstaw railsów będę miał jeszcze kiedykolwiek problem z wydawałoby się tak banalną akcją jak edit/update - no ale jednak zdarzyło się.
Edytuję model user, który korzysta z devise - domyślam się, że tu może tkwić problem.
Kod controllera:
[code=ruby] def edit
@user = User.find(params[:id])
end
def update
@user = User.find(params[:id])
if params[:user][:password]==''
params[:user].delete('password')
params[:user].delete('password_confirmation')
end
if @user.update_attributes(params[:user])
flash[:notice] = "Account updated."
redirect_to :action=>'index'
else
flash[:warning] = 'Something went wrong'
render :action => "edit"
end
end[/code]
Logi:
[code]Started GET “/accounts/edit/1” for 127.0.0.1 at 2010-03-23 11:53:24
Processing by AccountsController#edit as HTML
Parameters: {“id”=>“1”}
User Load (0.7ms) SELECT “users”.* FROM “users” WHERE (“users”.“id” = 1) LIMIT 1
CACHE (0.0ms) SELECT “users”.* FROM “users” WHERE (“users”.“id” = 1) LIMIT 1
DEPRECATION WARNING: Errors#on_base have been deprecated, use Errors#[:base] instead. (called from on_base at /Library/Ruby/Gems/1.8/gems/activemodel-3.0.0.beta/lib/active_model/deprecated_error_methods.rb:14)
Rendered accounts/edit.html.haml within layouts/application.html.haml (20.0ms)
Completed in 51ms (Views: 28.2ms | ActiveRecord: 0.6ms) with 200
Started POST “/accounts/1” for 127.0.0.1 at 2010-03-23 11:54:00
Processing by AccountsController#update as HTML
Parameters: {“commit”=>“Update User”, “authenticity_token”=>“GL8RppwXPIkM1qVfHKmZ+fn0iBKJjCEEXLDsyXtPkOQ=”, “id”=>“1”, “user”=>{“password_confirmation”=>"[FILTERED]", “phone”=>“123”, “password”=>"[FILTERED]", “email”=>"foo@bar.com"}}
User Load (0.7ms) SELECT “users”.* FROM “users” WHERE (“users”.“id” = 1) LIMIT 1
CACHE (0.0ms) SELECT “users”.* FROM “users” WHERE (“users”.“id” = 1) LIMIT 1
WARNING: Can’t mass-assign these protected attributes: phone, email
User Load (0.3ms) SELECT “users”.“id” FROM “users” WHERE (“users”.“email” = ‘foo@baz.com’) AND (“users”.id <> 1) LIMIT 1
Redirected to http://localhost:3000/accounts
Completed in 38ms with 302
Started GET “/accounts” for 127.0.0.1 at 2010-03-23 11:54:00
Processing by AccountsController#index as HTML
User Load (1.0ms) SELECT “users”.* FROM “users” WHERE (“users”.“id” = 1) LIMIT 1
Rendered accounts/index.html.haml within layouts/application.html.haml (32.3ms)
Completed in 64ms (Views: 39.2ms | ActiveRecord: 2.4ms) with 200[/code]
dodanie ! do update_attributes (nawet dodanie @user.save!) nie powoduje wywalenia exceptiona, cały czas otrzymuję informację, że konto zostało poprawione. Ma ktoś jakiekolwiek pomysły, czemu to może nie działać?
Aha, aplikacja działa na rails3