나는 새로운 Rails 응용 프로그램을 설치했고 인증을 위해 Authlogic을 사용하고 있습니다.AuthLogic UserSessions 컨트롤러 Nil을 반환
나는 행복하게 CRUD 할 수 있지만 사용자 세션에는 문제가있는 것으로 보입니다.
오류 메시지 :
undefined method `create' for nil:NilClass
app/controllers/user_sessions_controller.rb:9:in `create'
응용 프로그램/모델/user.rb
class User < ActiveRecord::Base
acts_as_authentic
end
응용 프로그램/컨트롤러/user_sessions_controller.rb
class UserSession < Authlogic::Session::Base
end
,536,913,632 10
응용 프로그램/모델/user_session.rb
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
응용 프로그램/뷰/user_sessions
= simple_form_for @user_session do |f|
= f.error_notification
= f.input :username, :label => false, :placeholder => "User name", :required => true, :input_html => {:size => 15, :class => "signin_input"}
= f.input :password, :label => false, :placeholder => "Password", :required => true, :input_html => {:size => 15, :class => "signin_input"}
= f.button :submit, "Sign in", :class => "a small"
dB/schema.rb
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"
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
설정/routes.rb
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 :: 세션에 문제 :: 자료 내가했습니다
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/[email protected]/gems/authlogic-3.1.0/lib/authlogic/session/activation.rb:47:in `initialize'
from /Users/vlad/.rvm/gems/[email protected]/gems/authlogic-3.1.0/lib/authlogic/session/klass.rb:55:in `initialize'
from /Users/vlad/.rvm/gems/[email protected]/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/[email protected]/gems/railties-3.1.3/lib/rails/commands/console.rb:45:in `start'
from /Users/vlad/.rvm/gems/[email protected]/gems/railties-3.1.3/lib/rails/commands/console.rb:8:in `start'
from /Users/vlad/.rvm/gems/[email protected]/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>'
것 같다 주위를 연주 후 편집 한 application_controller.rb 위의 오류를 극복하려고 시도하지만 여전히 동일한 결과
before_filter :activate_authlogic
private
def activate_authlogic
Authlogic::Session::Base.controller = Authlogic::ControllerAdapters::RailsAdapter.new(self)
end
루비 1.9.2 맥 OS X 10.7.2 (사자) 내가 무슨
를 놓친 거지?
이마 ... 슬랩 – vladiim
이러한 오타 관련 질문을 제거하여 [스택 오버플로 정리 캠페인] (http://meta.stackexchange.com/q/167342)이있어 정말 도움이됩니다. 이 질문에 가까운 표를 던지면서 조금 피칭해도 될까요? –