我创建了一个user_controller,它基本上使用以下语法扩展了设计用户设置:
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)
这有什么明显的错误吗?
答案 0 :(得分:0)
您的user_params
方法错误。它应该是:
params.require(:user).permit(:avatar, :email, :password, :password_confirmation)
答案 1 :(得分:0)
user_params
您需要这样做:
params.require(:user).permit(:avatar, :email, :password, :password_confirmation)
您可以阅读more