2012-03-24 69 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