我创建了一个user_controller,使用以下语法从根本上扩展了devise用户设置:
class UsersController < ApplicationController
def index
@users = User.order('created_at DESC').all
end
def create
@user = User.create(user_params)
end
private
def user_params
params.permit :user (:avatar, :email, :password, :password_confirmation )
end
end
在我的模型user.rb中,我有:
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
has_attached_file :avatar, styles: {
large: "600x450#",
medium: "250x250#",
small: "100x100#"
}, :default_url => "/images/:style/filler.png"
#validates_attachment_content_type :avatar, :content_type => ["image/jpg", "image/jpeg", "image/png", "image/gif"]
validates_attachment_content_type :avatar, :content_type => /\Aimage\/.*\Z/
validates :avatar, :email, :password, presence: true
end
这些都可以正常工作,但是当我重新加载页面时,我得到一个奇怪的错误,它说有语法错误,并且很奇怪,因为它在此之前就已经在工作了。我假设它与Rails版本有关的某种语法错误。
错误是:
Error details saved to: /tmp/passenger-error-9mVpXM.html
Message from application: /home/deployer/staging/releases/20140806094001/app/controllers/users_controller.rb:11: syntax error, unexpected ',', expecting ')'
...require(:user).permit (:avatar, :email, :password, :password...
... ^
/home/deployer/staging/releases/20140806094001/app/controllers/users_controller.rb:11: syntax error, unexpected ',', expecting :: or '[' or '.'
...it (:avatar, :email, :password, :password_confirmation )
... ^ (SyntaxError)
这有什么明显的错误吗?
您的user_params
方法是错误的。它应该是:
params.require(:user).permit(:avatar, :email, :password, :password_confirmation)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句