2012-03-24 68 views
0

Running Rails 3. 在用戶的模型文件中包含「include Rails.application.routes.url_helpers」。仍然收到此錯誤。任何想法??ruby​​ rails - 未定義的局部變量或方法`new_user_session_path'

# cat app/models/user.rb 
class User < ActiveRecord::Base 
include Rails.application.routes.url_helpers 
acts_as_authentic 
end 

# rake routes 
    users GET /users(.:format)   users#index 
      POST /users(.:format)   users#create 
new_user GET /users/new(.:format)  users#new 
edit_user GET /users/:id/edit(.:format) users#edit 
    user GET /users/:id(.:format)  users#show 
      PUT /users/:id(.:format)  users#update 
      DELETE /users/:id(.:format)  users#destroy 
    root  /      users#index 


# cat config/routes.rb | grep -v '#' 
www::Application.routes.draw do 
resources :users 
end 

錯誤 -

Showing /var/www/app/views/users/index.html.erb where line #7 raised: 

undefined local variable or method `new_user_session_path' for #<#<Class:0x9a51c6c>:0x9bb6170> 
Extracted source (around line #7): 

4: 
5: <p>Public Facing Content</p> 
6: 
7: <%= link_to 'Login', new_user_session_path %> 

回答

0

我相信你正在使用Authlogic?你是否生成了user_session類和控制器? https://github.com/binarylogic/authlogic_example

編輯: 嘗試增加

resources :user_session 

到routes.rb中

編輯2: 您正在關注一個很老的教程。現在我知道你在試圖達到什麼我建議你:

  1. 切換到設計。設計似乎贏得了作爲默認的導軌認證寶石。
  2. 從頭開始,並在嘗試使用Ajax進行驗證之前獲得認證正常工作。

+0

是。我正在使用authlogic,並生成了user_session類和控制器 – 2012-03-24 09:15:07

+0

您可以發佈您的routes.rb和rake路由的輸出嗎? – 2012-03-24 09:41:03

+0

'#耙路線 用戶獲得/users(.:format)用戶#指數 POST /users(.:format)用戶#創建 new_user GET /users/new(.:format)用戶#新 edit_user GET /用戶/:id/edit(.:format)users#edit user GET /users/:id(.:format)users#show PUT /users/:id(.:format)users#update DELETE/users /: id(。:format)users#destroy root/users#index #cat config/routes.rb | grep的-v「#」 WWW :: Application.routes.draw做 資源:用戶 end' – 2012-03-24 09:43:36