2016-12-12 1 views
0

作業が、私は、端末にログインchanged.The button.Theのリフレッシュページだけを押したときにPOST「/管理者/ユーザー/ 26/approve_vip」私はVIPであることをユーザーに承認する

Started POST "/admin/users/26/approve_vip" for ::1 at 2016-12-12 16:33:22 +0800 
Processing by Admin::UsersController#approve_vip as HTML 
    Parameters: {"authenticity_token"=>"qYrbaVH/cssY3VBYLw6Hd4wXl42Zz8OqkdHGGoITEeeWtbJ4ZOLOmJF/Jmpx70s9aaL5Yr0vFhqNV9kGHtILpA==", "user_id"=>"26"} 
User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? ORDER BY "users"."id" ASC LIMIT ? [["id", 4], ["LIMIT", 1]] 
User Load (0.1ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT ? [["id", 26], ["LIMIT", 1]] 
SQL (1.4ms) UPDATE "users" SET "is_vip" = 't' WHERE "users"."id" = ? [["id", 26]] 
(0.0ms) begin transaction 
(0.0ms) commit transaction 
DEPRECATION WARNING: `redirect_to :back` is deprecated and will be removed from Rails 5.1. Please use `redirect_back(fallback_location: fallback_location)` where `fallback_location` represents the location to use if the request has no HTTP referer information. (called from approve_vip at /Users/a1/JDDstore/app/controllers/admin/users_controller.rb:26) 
Redirected to http://localhost:3000/admin/users 
Completed 302 Found in 6ms (ActiveRecord: 1.7ms) 



Started POST "/admin/users/26/approve_vip" for ::1 at 2016-12-12 15:41:47 +0800 
Processing by Admin::UsersController#approve_vip as HTML 
    Parameters: {"authenticity_token"=>"uYc9hdEZaYCgfhdmYK3XnyK2lcraPpHWfuXcQ5cRtLyGuFSU5ATV0yncYVQ+TBvVxwP7Jf7eRGZiY8NfC9Cu/w==", "user_id"=>"26"} 
User Load (0.1ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? ORDER BY "users"."id" ASC LIMIT ? [["id", 4], ["LIMIT", 1]] 
User Load (0.1ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT ? [["id", 26], ["LIMIT", 1]] 
(0.0ms) begin transaction 
(0.0ms) commit transaction 
DEPRECATION WARNING: `redirect_to :back` is deprecated and will be removed from Rails 5.1. Please use `redirect_back(fallback_location: fallback_location)` where `fallback_location` represents the location to use if the request has no HTTP referer information. (called from approve_vip at /Users/a1/JDDstore/app/controllers/admin/users_controller.rb:26) 
Redirected to http://localhost:3000/admin/users 
Completed 302 Found in 4ms (ActiveRecord: 0.3ms) 
ありません

とコントローラのコードは

def approve_vip 
    @user = User.find(params[:user_id]) 
    @user.is_vip=true 
    @user.save  
    redirect_to :back 
end 

それは役割を変更しない理由を教えてもらえますでしょうか?
もっと情報を知りたい場合は、私に知らせてください。私を助けてくれてありがとう。

+0

ユーザーレコードの更新を担当するコードを追加します。 – dp7

+0

@ dp7質問を更新してください。〜thxを確認してください。 –

+0

コントローラのコードが間違って貼り付けられます。モデルのコードと同じです。 –

答えて

0

レコードの更新を制限しているモデルコールバック(before_save)があるようです。

update_columnまたはupdate_columnsを使用して、コールバック/検証をバイパスし、直接dbに更新クエリを作成できます。

def approve_vip 
    @user = User.find(params[:user_id]) 
    @user.update_columns(is_vip: true) 
    redirect_to :back 
end 
0

エラーのメッセージを読む必要があります。ユーザーの検証が失敗した可能性があります。

def approv! 
    update_attributes!(is_vip: true) 
end 

このコードでは、エラーのメッセージは例外です。

+0

私はこれを試みますが、それは動作しません。私は別のものとログを比較し、 "SQL(0.3ms)UPDATE"ユーザ "SET"ロール "=、" updated_at "=" WHERE "users"はありません。 "id" =?[["role"、0]、["updated_at"、2016-12-12 04:47:57 UTC]、["id"、29]] " –

+0

あなたはおそらく電話にアクセスできませんか? approve_vipメソッド?どんな役割のルール?前にbefore_filterコールがありますか? –

+0

これは "before_action:authenticate_user! before_action:require_is_admin"という2つのルールを持っていますが、コントローラ全体に適用されます。他の機能を通常どおりに使用できます。 –

関連する問題