ruby-on-rails-4sorcery

NoMethodError name RoR user.name


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

Solution

  • I took the long way home and cloned the Github repo. At first I was getting a 'stack level too deep' error, but I found that the gemfile loaded rails 4.2.1 . I changed this to 4.2.10 and all went well after the migrations and minor tweaks in the tutorial. along the way, I found rails_db gem which is a great simple gem for working with sqLite. rails_db gem