NoMethodError name RoR user.name

时间:2018-03-25 20:38:48

标签: ruby-on-rails-4 sorcery

Followed the tutorial at SitePoint

for a simple sorcery app. I am receiving undefined method `name' for nil:NilClass

migration

class SorceryCore < ActiveRecord::Migration
  def change
   create_table :users do |t|
      t.string :name
      t.string :email,            :null => false
      t.string :crypted_password
      t.string :salt

      t.timestamps                :null => false
    end

    add_index :users, :email, unique: true
  end
end

/home/david/Magical/app/views/user_mailer/activation_needed_email.html.erb

<p>Welcome, <%= @user.name %>!</p>

<p>To login to the site, just follow <%= link_to 'this link', 
activate_user_url$

<p>Thanks for joining and have a great day!</p>

users.rb

class User < ActiveRecord::Base
  authenticates_with_sorcery!
  validates :password, length: { minimum: 3 }
  validates :password, confirmation: true
  validates :email, uniqueness: true, email_format: { message: 'has 
  invalid format'
End

1 个答案:

答案 0 :(得分:0)

我走了很长的路回家并克隆了Github回购。起初我得到了“堆栈级太深”错误,但我发现gemfile加载了rails 4.2.1。 我将其更改为4.2.10,并且在教程中的迁移和小调整之后一切顺利。 一路走来,我找到了rails_db gem,这是一个非常简单的gem,用于处理sqLite。 rails_db gem