RailsApps / rails-devise-pundit

Rails 5.0 starter app with Devise for authentication and Pundit for authorization.
http://railsapps.github.io/rails-devise-pundit/
485 stars 156 forks source link

admin and user are mixed up in the seeds.rb file #1

Closed franzen closed 10 years ago

franzen commented 10 years ago

Hi, in the db/seeds.rb file you do a user.confirm!, but the correct variable should be admin.confirm!

# This file should contain all the record creation needed to seed the database with its default values.
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
#
# Examples:
#
#   cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
#   Mayor.create(name: 'Emanuel', city: cities.first)
admin = CreateAdminService.new.call
puts 'CREATED ADMIN USER: ' << admin.email
user.confirm!

I created the rails app with the following options:

rails new foobar -m https://raw.github.com/RailsApps/rails-composer/master/composer.rb
      recipe  Running railsapps recipe...
    question  Build a starter application?
          1)  Build a RailsApps example application
          2)  Build a contributed application
          3)  I want to build my own application
   railsapps  Enter your selection: 1
    question  Starter apps for Rails 4.1. More to come.
          1)  rails-bootstrap
          2)  rails-foundation
          3)  rails-omniauth
          4)  rails-devise
          5)  rails-devise-pundit
   railsapps  Enter your selection: 5
      recipe  Running setup recipe...
       setup  Your operating system is darwin13.0.0.
       setup  You are using Ruby version 2.0.0.
       setup  You are using Rails version 4.1.0.rc1.
    question  Web server for development?
          1)  WEBrick (default)
          2)  Thin
          3)  Unicorn
          4)  Puma
          5)  Phusion Passenger (Apache/Nginx)
          6)  Phusion Passenger (Standalone)
       setup  Enter your selection: 3
    question  Web server for production?
          1)  Same as development
          2)  Thin
          3)  Unicorn
          4)  Puma
          5)  Phusion Passenger (Apache/Nginx)
          6)  Phusion Passenger (Standalone)
       setup  Enter your selection: 3
    question  Database used in development?
          1)  SQLite
          2)  PostgreSQL
          3)  MySQL
          4)  MongoDB
       setup  Enter your selection: 1
    question  Template engine?
          1)  ERB
          2)  Haml
          3)  Slim
       setup  Enter your selection: 1
    question  Continuous testing?
          1)  None
          2)  Guard
       setup  Enter your selection: 2
    question  Front-end framework?
          1)  None
          2)  Bootstrap 3.0
          3)  Bootstrap 2.3
          4)  Zurb Foundation 5.0
          5)  Zurb Foundation 4.0
          6)  Simple CSS
       setup  Enter your selection: 2
       setup  The Devise 'forgot password' feature requires email.
    question  Add support for sending email?
          1)  None
          2)  Gmail
          3)  SMTP
          4)  SendGrid
          5)  Mandrill
       setup  Enter your selection: 4
    question  Devise modules?
          1)  Devise with default modules
          2)  Devise with Confirmable module
          3)  Devise with Confirmable and Invitable modules
       setup  Enter your selection: 3
    question  Use a form builder gem?
          1)  None
          2)  SimpleForm
       setup  Enter your selection: 2
...
      extras  Set a robots.txt file to ban spiders? (y/n) y
      extras  Create a GitHub repository? (y/n) n
      extras  Use or create a project-specific rvm gemset? (y/n) n
....
rake aborted!
undefined local variable or method `user' for main:Object
/Users/adc/Peerialism/hive-portal/db/seeds.rb:10:in `<top (required)>'
/Users/adc/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.1.0.rc1/lib/active_support/dependencies.rb:241:in `load'
/Users/adc/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.1.0.rc1/lib/active_support/dependencies.rb:241:in `block in load'
/Users/adc/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.1.0.rc1/lib/active_support/dependencies.rb:232:in `load_dependency'
/Users/adc/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.1.0.rc1/lib/active_support/dependencies.rb:241:in `load'
/Users/adc/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.1.0.rc1/lib/rails/engine.rb:544:in `load_seed'
/Users/adc/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.1.0.rc1/lib/active_record/tasks/database_tasks.rb:184:in `load_seed'
/Users/adc/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.1.0.rc1/lib/active_record/railties/databases.rake:173:in `block (2 levels) in <top (required)>'
/Users/adc/.rvm/gems/ruby-2.0.0-p247/bin/ruby_executable_hooks:15:in `eval'
/Users/adc/.rvm/gems/ruby-2.0.0-p247/bin/ruby_executable_hooks:15:in `<main>'
Tasks: TOP => db:seed
...
DanielKehoe commented 10 years ago

I've resolved this issue by changing the variable admin to user.

Also I've moved the user.confirm! action to the CreateAdminService object when "Devise with Confirmable" is selected.

Please let me know if you see any problems.