ruby rails - 未定义的局部变量或方法“new_user_session_path" [英] ruby rails - undefined local variable or method `new_user_session_path'
问题描述
运行 Rails 3.在用户的模型文件中包含include Rails.application.routes.url_helpers".仍然收到此错误.任何想法??
Running Rails 3. Included "include Rails.application.routes.url_helpers" in model file of users. Still getting this error. Any idea??
# 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 %>
推荐答案
我猜你在使用 Authlogic?您是否生成了 user_session 类和控制器?https://github.com/binarylogic/authlogic_example
I presume you are using Authlogic? Have you generated the user_session class and controller? https://github.com/binarylogic/authlogic_example
尝试添加
resources :user_session
到routes.rb
您正在学习一个相当古老的教程.现在我知道你想要达到的目标,我建议你:
Edit 2: You are following quite an old tutorial. Now I know what you are trying to achieve I suggest you:
- 切换到设计.Devise 似乎已经成为默认的 Rails 身份验证宝石.
在尝试使用 Ajax 之前从头开始并让身份验证正常工作.
- Switch to Devise. Devise seems to have won out as the default rails authentication gem.
Start from scratch and get authentication working properly before trying to do it with Ajax.
- 设计:https://github.com/plataformatec/devise
- 教程:http://railsapps.github.com/tutorial-rails-devise-rspec-cucumber.html
这篇关于ruby rails - 未定义的局部变量或方法“new_user_session_path"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!