2013-08-28 163 views
1

一直在努力讓我的網站上Heroku,並意識到我沒有添加//= require_tree .到我的application.js文件,我相信這是爲什麼我的JS文件沒有被加載。Rails未定義方法user_signed_in?

添加後,我在生產模式下推到Heroku,並得到錯誤「undefined method'user_signed_in?' #<#:0x00000003fd2d18>「

我試過將我的意見中所有對user_signed_in?的引用改爲signed_in?(:user),但它沒有區別。我正在運行Rails 3.2.13,這就是我在Gemfile中獲得Devise gem的方式:

gem "devise", :git => "git://github.com/plataformatec/devise.git" 

有什麼建議嗎?

UPDATE - routes.rb中

BrainDb::Application.routes.draw do 

devise_for :users 

resources :submissions 
get "/submissions/new(.:format)" => "submissions#new" 
get "/submissions/:id(.:format)" => "submissions#show" 
post "/submissions/:id(.:format)" => "submissions#update" 

resources :folders 

root to: 'home#index' 

scope "api" do 
get "/submissions(.:format)" => "submissions#index" 
get "/submissions/:id(.:format)" => "submissions#show" 
get "/:user_id/submissions(.:format)" => "submissions#usercontent" 
get "/:user_id/submissions/:id(.:format)" => "submissions#usersubmission" 



get "/:user_id/folders(.:format)" => "folders#userfolders" 

get "/submissions/:id/edit(.:format)" => "submissions#edit" 

get "/folders/new(.:format)" => "folders#new" 

end 

的application.js:

//= require jquery 
//= require jquery_ujs 
//= require_tree . 

Application.html.erb,我使用它:

<% if user_signed_in? %> 

<div id="fixed_nav"> 
<h3 id="logo"><a href="/">chakra</a></h3> 
<%= form_tag(folders_path, :method => "get", class: "navbar-form", id: "search-form") do %> 
    <div class="input-append"> 
     <%= text_field_tag :search, params[:search], placeholder: "Search for anything", :class => "form-field" %> 
     <button class="btn btn-edit" type="submit form-submit"><i class="icon-search"></i></button> 
    </div> 
<% end %> 
<div id="settings-links"> 
    <%= link_to "Settings", edit_user_registration_path, :method => :get %> 
    <%= link_to "Sign out", destroy_user_session_path, :method => :delete %> 
</div> 
</div> 

<% else %> 

<div id="fixed_nav"> 
<h3><a href="/">chakra</a></h3> 
</div> 

<% end %> 

User.rb:

class User < ActiveRecord::Base 
# Include default devise modules. Others available are: 
# :token_authenticatable, :confirmable, 
# :lockable, :timeoutable and :omniauthable 
devise :database_authenticatable, :registerable, 
    :recoverable, :rememberable, :trackable, :validatable 

# Setup accessible (or protected) attributes for your model 
attr_accessible :email, :password, :password_confirmation, :remember_me, :user_id, :submissions, :folders 
# attr_accessible :title, :body 

has_many :submissions 
has_many :folders 

end 
+0

是否有用戶模式?您是否使用設計創建了用戶模型? rails generate devise MODEL – techvineet

+0

是的,我已經在本地運行了幾個月的應用程序。設計和用戶模型在我移除require_tree行時工作,但顯然我的JS資源的其餘部分不加載。 –

+0

發佈您的config/routes.rb並檢查設計:database_authenticatable在您的用戶模型中。 – techvineet

回答

0

有時,ApplicationController中的方法'clear_helpers'阻塞Devise來加載他的助手。

刪除此方法應該是您的綠燈。

config.action_controller.include_all_helpers = false 

在application.rb中

相關問題