简体   繁体   English

SessionsController#create中的NoMethodError

[英]NoMethodError in SessionsController#create

Ok, I'm learning R on R from the Pragmatic Bookshelf text Agile Webdevelopment with Rails 4th ed. 好的,我正在从带Rails第四版的实用书架文本Agile Webdevelopment中学习R onR。

I'm at page 212 and I'm getting this error.... NoMethodError in SessionsController#create and app/controllers/sessions_controller.rb:7:in 'create' 我在第212页,但出现此错误。... NoMethodError in SessionsController#createapp/controllers/sessions_controller.rb:7:in 'create' NoMethodError in SessionsController#create

I'm pulling my beard out over here, I've spent days trying to track this down. 我要把胡须拉到这里,我花了几天的时间试图找出答案。 Here is the create code this is pointing to... 这是它指向的创建代码...

def create
  if user = User.authenticate(params[:name], params[:password])
    session[:user_id] = user.id
    redirect_to admin_url
  else
    redirect_to login_url, :alert => "Invalid user/password combination"
  end
end

Can any Guru out there assist? 那里的任何一位上师可以协助吗?

Sounds like you need the following in your user model (page 203 on my book.) If that is not the issue, please provide your user model too. 听起来您的用户模型中需要以下内容(我的书的第203页。)如果这不是问题,请也提供您的用户模型。

def User.authenticate(name, password)
  if user = find_by_name(name)
    if user.hashed_password == encrypt_password(password, user.salt)
      user
    end
  end
end

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 SessionsController#create中的NoMethodError - NoMethodError in SessionsController#create Api :: SessionsController#create中的NoMethodError - NoMethodError in Api::SessionsController#create rails 4:Devise :: SessionsController#create中的NoMethodError - rails 4 : NoMethodError in Devise::SessionsController#create SessionsController#NoilMethodError为nil:NilClass创建未定义的方法“ []” - NoMethodError in SessionsController#create undefined method `[]' for nil:NilClass SessionsController#中的Rails 4 NoMethodError为nil:NilClass创建未定义的方法&#39;slice&#39; - Rails 4 NoMethodError in SessionsController#create undefined method `slice' for nil:NilClass SessionsController#create中的NoMethodError-#的未定义方法&#39;[]&#39; <Oauth::Access_Token…> - NoMethodError in SessionsController#create - Undefined method '[]' for #<Oauth::Access_Token…> 设计中的 NoMethodError::SessionsController#create undefined method `current_sign_in_at&#39; - NoMethodError in Devise::SessionsController#create undefined method `current_sign_in_at' Rails Devise LDAP错误:Devise :: SessionsController#create中的NoMethodError - Rails Devise LDAP Error: NoMethodError in Devise::SessionsController#create 在用户模型中调用方法时,SessionsController#create中的NoMethodError - NoMethodError in SessionsController#create when calling a method in user model 使用Omniauth Facebook身份验证Railscast 360在SessionsController#create中出现NoMethodError - NoMethodError in SessionsController#create using Omniauth Facebook authentication railscast 360
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM