Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails AuthLogic用户会话控制器返回Nil_Ruby On Rails_Ruby On Rails 3_Ruby On Rails 3.1_Authlogic_Null - Fatal编程技术网

Ruby on rails AuthLogic用户会话控制器返回Nil

Ruby on rails AuthLogic用户会话控制器返回Nil,ruby-on-rails,ruby-on-rails-3,ruby-on-rails-3.1,authlogic,null,Ruby On Rails,Ruby On Rails 3,Ruby On Rails 3.1,Authlogic,Null,我已经安装了一个新的Rails应用程序,正在使用Authlogic进行身份验证 我可以很高兴地CRUD用户,但用户会话似乎有问题 错误消息: undefined method `create' for nil:NilClass app/controllers/user_sessions_controller.rb:9:in `create' app/models/user.rb class User < ActiveRecord::Base acts_as_authentic end

我已经安装了一个新的Rails应用程序,正在使用Authlogic进行身份验证

我可以很高兴地CRUD用户,但用户会话似乎有问题

错误消息:

undefined method `create' for nil:NilClass
app/controllers/user_sessions_controller.rb:9:in `create'
app/models/user.rb

class User < ActiveRecord::Base
  acts_as_authentic
end
class UserSession < Authlogic::Session::Base
end
class UserSessionsController < ApplicationController

  def new
    @user_sesssion = UserSession.new
  end    

  def create
    @user_sesssion = UserSession.new(params[:user_session])
    if @user_session.create 
      flash[:notice] = "Welcome back!"
      redirect_to root_path
    else
      render :new
    end
  end

  def destroy
    @user_session = UserSession.find
    @user_session.destroy
    redirect_to root_path
  end
end
  create_table "users", :force => true do |t|
    t.string   "username",          :null => false
    t.string   "email",             :null => false
    t.string   "crypted_password",  :null => false
    t.string   "password_salt",     :null => false
    t.string   "persistence_token", :null => false
    t.string   "perishable_token"
    t.datetime "created_at"
    t.datetime "updated_at"
  end

  add_index "users", ["email"], :name => "index_users_on_email"
  add_index "users", ["perishable_token"], :name => "index_users_on_perishable_token"
  add_index "users", ["persistence_token"], :name => "index_users_on_persistence_token"
  add_index "users", ["username"], :name => "index_users_on_username"
  resource :users
  resource :user_sessions 

  match 'signin', :to => "user_sessions#new"
  match 'signout', :to => "user_sessions#destroy"

  get "pages/home"
  root :to => 'pages#home'
db/schema.rb

class User < ActiveRecord::Base
  acts_as_authentic
end
class UserSession < Authlogic::Session::Base
end
class UserSessionsController < ApplicationController

  def new
    @user_sesssion = UserSession.new
  end    

  def create
    @user_sesssion = UserSession.new(params[:user_session])
    if @user_session.create 
      flash[:notice] = "Welcome back!"
      redirect_to root_path
    else
      render :new
    end
  end

  def destroy
    @user_session = UserSession.find
    @user_session.destroy
    redirect_to root_path
  end
end
  create_table "users", :force => true do |t|
    t.string   "username",          :null => false
    t.string   "email",             :null => false
    t.string   "crypted_password",  :null => false
    t.string   "password_salt",     :null => false
    t.string   "persistence_token", :null => false
    t.string   "perishable_token"
    t.datetime "created_at"
    t.datetime "updated_at"
  end

  add_index "users", ["email"], :name => "index_users_on_email"
  add_index "users", ["perishable_token"], :name => "index_users_on_perishable_token"
  add_index "users", ["persistence_token"], :name => "index_users_on_persistence_token"
  add_index "users", ["username"], :name => "index_users_on_username"
  resource :users
  resource :user_sessions 

  match 'signin', :to => "user_sessions#new"
  match 'signout', :to => "user_sessions#destroy"

  get "pages/home"
  root :to => 'pages#home'
Gemfile

gem 'rails', '3.1.3'
gem 'pg'
gem 'heroku'
gem 'authlogic'
gem 'will_paginate'
gem 'simple_form'

group :assets do
  gem 'sass-rails',   '~> 3.1.5'
  gem 'coffee-rails', '~> 3.1.1'
  gem 'uglifier', '>= 1.0.3'
  gem 'haml-rails'
  gem 'zurb-foundation'
end

gem 'jquery-rails'


gem 'rspec-rails', :group => [:test, :development]

group :test do
  gem 'factory_girl_rails'
  gem 'capybara'
  gem 'guard-rspec'
end 
config/routes.rb

class User < ActiveRecord::Base
  acts_as_authentic
end
class UserSession < Authlogic::Session::Base
end
class UserSessionsController < ApplicationController

  def new
    @user_sesssion = UserSession.new
  end    

  def create
    @user_sesssion = UserSession.new(params[:user_session])
    if @user_session.create 
      flash[:notice] = "Welcome back!"
      redirect_to root_path
    else
      render :new
    end
  end

  def destroy
    @user_session = UserSession.find
    @user_session.destroy
    redirect_to root_path
  end
end
  create_table "users", :force => true do |t|
    t.string   "username",          :null => false
    t.string   "email",             :null => false
    t.string   "crypted_password",  :null => false
    t.string   "password_salt",     :null => false
    t.string   "persistence_token", :null => false
    t.string   "perishable_token"
    t.datetime "created_at"
    t.datetime "updated_at"
  end

  add_index "users", ["email"], :name => "index_users_on_email"
  add_index "users", ["perishable_token"], :name => "index_users_on_perishable_token"
  add_index "users", ["persistence_token"], :name => "index_users_on_persistence_token"
  add_index "users", ["username"], :name => "index_users_on_username"
  resource :users
  resource :user_sessions 

  match 'signin', :to => "user_sessions#new"
  match 'signout', :to => "user_sessions#destroy"

  get "pages/home"
  root :to => 'pages#home'
在进行了更多的尝试之后,Authlogic::Session::Base似乎出现了一个问题

1.9.2-p290 :019 > session = UserSession.new(:username => "test", :password => "password")
Authlogic::Session::Activation::NotActivatedError: You must activate the Authlogic::Session::Base.controller with a controller object before creating objects
    from /Users/vlad/.rvm/gems/ruby-1.9.2-p290@fitafy/gems/authlogic-3.1.0/lib/authlogic/session/activation.rb:47:in `initialize'
    from /Users/vlad/.rvm/gems/ruby-1.9.2-p290@fitafy/gems/authlogic-3.1.0/lib/authlogic/session/klass.rb:55:in `initialize'
    from /Users/vlad/.rvm/gems/ruby-1.9.2-p290@fitafy/gems/authlogic-3.1.0/lib/authlogic/session/scopes.rb:79:in `initialize'
    from (irb):19:in `new'
    from (irb):19
    from /Users/vlad/.rvm/gems/ruby-1.9.2-p290@fitafy/gems/railties-3.1.3/lib/rails/commands/console.rb:45:in `start'
    from /Users/vlad/.rvm/gems/ruby-1.9.2-p290@fitafy/gems/railties-3.1.3/lib/rails/commands/console.rb:8:in `start'
    from /Users/vlad/.rvm/gems/ruby-1.9.2-p290@fitafy/gems/railties-3.1.3/lib/rails/commands.rb:40:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'
Ruby 1.9.2 Mac OS X 10.7.2(Lion)


我在这里遗漏了什么?

您输入了一个拼写错误,您用额外的s拼写了
user\u session
。此外,您想在会话中调用的是
save
,而不是'create.

通过删除这些与打字相关的问题,我们真的需要您的帮助!你介意在这个问题上投一票吗?