2
不工作我使用的設計和Rails 4更新的用戶名在設計
當我去編輯用戶並修改用戶名,我打了更新,但新的用戶名沒有在DB修改。更新密碼和電子郵件都能正常工作,只是用戶名似乎受到影響。我發現了similar question,但據我所知,我沒有可能導致此問題的before_save動作。
當軌道Console這是我所看到的之前,我執行更新操作,當我做User.first:
=> #<User id: 1, email: "[email protected]", created_at: "2017-03-03 19:10:48", updated_at: "2017-05-18 00:52:28", username: "blueduckyy", avatar_file_name: nil, avatar_content_type: nil, avatar_file_size: nil, avatar_updated_at: nil>
當我執行更新操作,我認爲這是終端窗口:
Parameters: {"utf8"=>"✓", "authenticity_token"=>"tFn+73EVxXbaZ4jgVen1iGB5U2yllqbyf/G+nL0Xp+xyRxQQtS2Eq3WTkJi7b1PP/FjduC6kC3X5ERgErjA+Vg==", "user"=>{"username"=>"blueduckyy2"}, "commit"=>"Save"}
在瀏覽器中,我收到一條響應,表示用戶已成功更新。
然後,如果我再次執行User.first,我會得到與上面相同的內容。
這是我在我的應用程序控制器:
def configure_permitted_parameters
devise_parameter_sanitizer.permit(:sign_up, keys: [:username])
end
如果有關,我的註冊記憶控制器,可我重寫了色器件:
class Users::RegistrationsController < Devise::RegistrationsController
protected
def update_resource(resource, params)
resource.update_without_password(params)
end
def after_update_path_for(resource)
user_path(resource)
end
end
我的用戶模型:
class User < ApplicationRecord
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
validates :username, presence: true, length: { maximum: 15 }, uniqueness: {case_sensitive: false}
has_attached_file :avatar, :styles => { :medium => "300x300>",:small => "200x200", :thumb => "100x100" }, :default_url => "/images/:style/missing.png"
validates_attachment_content_type :avatar, :content_type => /\Aimage\/.*\Z/
end
你有'before_action:configure_permitted_parameters,如果:devise_controller'的'ApplicationController'? – jdgray
@jdgray是的,我願意! – blueduckyy