1
請幫我使用rails 3.2.11和devise 2.0.6,但是當我嘗試運行我的項目時出現錯誤undefined method`user_signed_in?'對於類 我做了很多谷歌,但沒有找到任何解決方案。設計:未定義的方法`user_signed_in?不知道爲什麼?
下面是我應用程序跟蹤
NoMethodError in Home#index
Showing /home/amits/RailsWorkspace/Myapp/app/views/home/index.html.haml where line #3 raised:
undefined method `user_signed_in?' for #<#<Class:0xbb1f3f4>:0xbae60b8>
Extracted source (around line #3):
1: %h2= (t :welcome) + " Myapp"
2:
3: - if user_signed_in?
4: = link_to (I18n.t :customers), user_root_path
5: /%li
6: /= link_to (I18n.t :sign_out), destroy_user_session_path, :method => :delete
Rails.root: /home/amits/RailsWorkspace/Myapp
Application Trace | Framework Trace | Full Trace
app/views/home/index.html.haml:3:in `_app_views_home_index_html_haml___806580830_97751900'
Request
Parameters:
None
Show session dump
Show env dump
Response
Headers:
None
和我的寶石文件如下
的Gemfile:
source 'https://rubygems.org'
gem 'rails', '3.2.11'
gem 'heroku'
gem 'pg'
gem 'haml'
gem 'haml-rails', :group => :development
gem 'rmagick'
group :assets do
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.0'
gem 'uglifier', '>= 1.0.3'
end
gem "devise", "~> 2.0.0"
gem 'devise_aes_encryptable'
# version added so that the gem version will be stable at this point.
gem 'geokit', '1.5.0'
gem 'geokit-rails3', '0.1.5'
我的首頁控制器
Homescontroller.rb
class HomeController < ApplicationController
before_filter :authenticate_user!
def index
end
end
我的用戶模型
User.rb
class User < ActiveRecord::Base
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable, :token_authenticatable, :omniauthable
# Setup accessible (or protected) attributes for your model
attr_accessible :email, :password, :password_confirmation, :remember_me, :sign_in_count
end
Rotes.rb
Myapp::Application.routes.draw do
devise_for :users
root to: "home#index"
end
請幫我....
你有沒有叫過:authenticate_user!在你的控制器? – Nathan
是的,我有我的家庭控制器檢查我編輯的問題 –