2013-05-29 31 views
0

我正在關注如何使用jruby和登錄系統創建在線應用程序的webtutorial。我對jruby很陌生,如果我遺漏了任何重要信息,我很抱歉。未定義的方法demodulize爲零:NilClass在AuthLogic應用程序

我有一個username模型和user_login模型,我認爲是正確的。我收到的錯誤是當我嘗試創建新的user_login會話。從本質上講,我可以註冊一個用戶,但一旦我user_login控制器調用@user_login = UserLogin.new,系統崩潰了以下消息:

 
undefined method `demodulize' for nil:NilClass 
Rails.root: /home/eoin/programming/year/website 

Application Trace | Framework Trace | Full Trace 
authlogic (3.3.0) lib/authlogic/session/klass.rb:52:in `initialize' 
authlogic (3.3.0) lib/authlogic/session/scopes.rb:79:in `initialize' 
app/controllers/user_logins_controller.rb:6:in `new' 
org/jruby/RubyBasicObject.java:1659:in `__send__' 
org/jruby/RubyKernel.java:2086:in `send' 
actionpack (3.2.13) lib/action_controller/metal/implicit_render.rb:4:in `send_action' 
actionpack (3.2.13) lib/abstract_controller/base.rb:167:in `process_action' 
... 

我的控制器類看起來是這樣的:

class UserLoginsController < ApplicationController 

# GET /user_logins/new 
# GET /user_logins/new.json 
def new 
@user_login = UserLogin.new 

respond_to do |format| 
    format.html # new.html.erb 
    format.xml { render :xml => @user_login } 
end 
end 



# POST /user_logins 
# POST /user_logins.json 
def create 
@user_login = UserLogin.new(params[:user_login]) 

respond_to do |format| 
    if @user_login.save 
    format.html { redirect_to(:usernames, :notice => 'Login Successful') } 
    format.xml { render :xml => @user_login, :status => :created, :location => @user_login } 
    else 
    format.html { render action: "new" } 
    format.json { render json: @user_login.errors, status: :unprocessable_entity } 
    end 
end 
end 


# DELETE /user_logins/1 
# DELETE /user_logins/1.json 
def destroy 
@user_login = UserLogin.find 
@user_login.destroy 

respond_to do |format| 
    format.html { redirect_to(:usernames, :notice => 'Goodbye!') } 
    format.json { head :ok } 
end 
end 
end 

我執行程序在Ubuntu上,不知道該怎麼做。這個問題在網上似乎沒有幫助。任何有關如何解決這個問題的建議都會非常困難。 感謝

哦,這裏是我的gemlock文件中看到我已經安裝了哪些寶石。

 remote: http://rubygems.org/ 
specs: 
    actionmailer (3.2.13) 
    actionpack (= 3.2.13) 
    mail (~> 2.5.3) 
actionpack (3.2.13) 
    activemodel (= 3.2.13) 
    activesupport (= 3.2.13) 
    builder (~> 3.0.0) 
    erubis (~> 2.7.0) 
    journey (~> 1.0.4) 
    rack (~> 1.4.5) 
    rack-cache (~> 1.2) 
    rack-test (~> 0.6.1) 
    sprockets (~> 2.2.1) 
activemodel (3.2.13) 
    activesupport (= 3.2.13) 
    builder (~> 3.0.0) 
activerecord (3.2.13) 
    activemodel (= 3.2.13) 
    activesupport (= 3.2.13) 
    arel (~> 3.0.2) 
    tzinfo (~> 0.3.29) 
activerecord-jdbc-adapter (1.2.9) 
activerecord-jdbcsqlite3-adapter (1.2.9) 
    activerecord-jdbc-adapter (~> 1.2.9) 
    jdbc-sqlite3 (~> 3.7.2) 
activeresource (3.2.13) 
    activemodel (= 3.2.13) 
    activesupport (= 3.2.13) 
activesupport (3.2.13) 
    i18n (= 0.6.1) 
    multi_json (~> 1.0) 
arel (3.0.2) 
authlogic (3.3.0) 
    activerecord (>= 3.2) 
    activesupport (>= 2.3) 
bouncy-castle-java (1.5.0147) 
builder (3.0.4) 
coffee-rails (3.2.2) 
    coffee-script (>= 2.2.0) 
    railties (~> 3.2.0) 
coffee-script (2.2.0) 
    coffee-script-source 
    execjs 
coffee-script-source (1.6.2) 
erubis (2.7.0) 
execjs (1.4.0) 
    multi_json (~> 1.0) 
hike (1.2.2) 
i18n (0.6.1) 
jdbc-sqlite3 (3.7.2.1) 
journey (1.0.4) 
jquery-rails (3.0.0) 
    railties (>= 3.0, < 5.0) 
    thor (>= 0.14, < 2.0) 
jruby-openssl (0.8.8) 
    bouncy-castle-java (>= 1.5.0147) 
json (1.8.0) 
json (1.8.0-java) 
mail (2.5.4) 
    mime-types (~> 1.16) 
    treetop (~> 1.4.8) 
mime-types (1.23) 
multi_json (1.7.4) 
polyglot (0.3.3) 
rack (1.4.5) 
rack-cache (1.2) 
    rack (>= 0.4) 
rack-ssl (1.3.3) 
    rack 
rack-test (0.6.2) 
    rack (>= 1.0) 
rails (3.2.13) 
    actionmailer (= 3.2.13) 
    actionpack (= 3.2.13) 
    activerecord (= 3.2.13) 
    activeresource (= 3.2.13) 
    activesupport (= 3.2.13) 
    bundler (~> 1.0) 
    railties (= 3.2.13) 
railties (3.2.13) 
    actionpack (= 3.2.13) 
    activesupport (= 3.2.13) 
    rack-ssl (~> 1.3.2) 
    rake (>= 0.8.7) 
    rdoc (~> 3.4) 
    thor (>= 0.14.6, < 2.0) 
rake (10.0.4) 
rdoc (3.12.2) 
    json (~> 1.4) 
sass (3.2.9) 
sass-rails (3.2.6) 
    railties (~> 3.2.0) 
    sass (>= 3.1.10) 
    tilt (~> 1.3) 
sprockets (2.2.2) 
    hike (~> 1.2) 
    multi_json (~> 1.0) 
    rack (~> 1.0) 
    tilt (~> 1.1, != 1.3.0) 
sqlite3 (1.3.7) 
thor (0.18.1) 
tilt (1.4.1) 
treetop (1.4.12) 
    polyglot 
    polyglot (>= 0.3.1) 
tzinfo (0.3.37) 
uglifier (2.1.1) 
    execjs (>= 0.3.0) 
    multi_json (~> 1.0, >= 1.0.2) 

請問,我會提出任何額外的代碼。

回答

0

如果不使用所提供的示例類名(似乎是Authlogic教程),那麼你就需要指定它需要進行身份驗證,例如什麼型號:

class UserLogin < Authlogic::Session::Base 
    authenticate_with Username 
end 

這樣,您告訴UserLogin類需要檢查用戶名模型以驗證身份驗證憑據。

你沒有發佈你的模型代碼,所以我猜這就是它的命名方式。

相關問題