Tôi đang thiết lập và cần có khả năng sử dụng người trợ giúp sáng tạo. Khi tôi thêm before_filter :authenticate_user!
vào bộ điều khiển ứng dụng tôi nhận được lỗi sau undefined method 'authenticate_user!' for #<HomeController:*>
Devise Helpers (authenticate_user !, current_user, user_signed_in?) Không được khởi tạo
Nó không phải là hiện diện trong bộ điều khiển nhà tôi trực tiếp, nhưng được thừa hưởng từ bộ điều khiển ứng dụng, nếu tôi sử dụng skip_before_filter :authenticate_user!
trong nhà của tôi (hoặc bất kỳ bộ điều khiển) và cố gắng để truy cập trang tôi nhận được lỗi sau.
undefined method `user_signed_in?' for #<#<Class *>
Nó vi phạm trên dòng trong tệp bố cục/application.html.erb gọi nó. Điều tương tự cũng xảy ra với bất kỳ người trợ giúp nào. Có vẻ như họ không được nạp ở tất cả, tuy nhiên, khi tôi tải lên các đường ray giao diện điều khiển, và bước vào $LOAD_PATH.dup
đầu ra bao gồm
"/usr/local/rvm/gems/ruby-1.9.3-p429/gems/devise-2.2.4/lib", "/usr/local/rvm/gems/ruby-1.9.3-p429/gems/devise-2.2.4/app/controllers", "/usr/local/rvm/gems/ruby-1.9.3-p429/gems/devise-2.2.4/app/helpers", "/usr/local/rvm/gems/ruby-1.9.3-p429/gems/devise-2.2.4/app/mailers"
Vì vậy, có vẻ như họ thực sự cần được nạp bởi đường ray.
Đây là bộ điều khiển ứng dụng của tôi
lớp ApplicationController < ActionController :: Base
helper: tất cả # bao gồm tất cả những người giúp đỡ, tất cả các thời gian
protect_from_forgery
bao gồm ActionView :: Helpers: : NumberHelper
before_filter: authenticate_user!cuối
tôi đã khởi động lại máy chủ sau khi cài đặt đưa ra, và nhiều lần như tôi đã cố gắng nỗ lực khác nhau để giải quyết vấn đề. Nếu cần thêm bất kỳ tệp hoặc thông tin nào, vui lòng cho tôi biết. Cảm ơn bạn rất nhiều trước.
Chỉnh sửa: tập tin user.rb tôi đã được yêu cầu để chứng minh rằng tôi đã thực sự được cài đặt đưa ra
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,
:encryptable, :encryptor => :restful_authentication_sha1
# Setup accessible (or protected) attributes for your model
attr_accessible :email, :password, :password_confirmation, :remember_me
end
Chỉnh sửa: Toàn bộ thông báo lỗi
NoMethodError trong HomeController # index
không xác định phương thức `authenticate_user! ' cho # < HomeController: 0x000000040c45a0> '
Dưới đây là toàn bộ dấu vết
activesupport (3.2.13) lib/active_support/callbacks.rb: 418: trong `chạy _2094683035699451847__process_action_ _callbacks '
activesupport (3.2.13) lib/active_support/callbacks.rb: 405: trong `__run_callback'
activesupport (3.2.13) lib/active_support/callbacks.rb: 385: trong> `
activesupport (3.2.13) lib/active_support/callbacks.rb: 81: trong` run_callbacks' _run_process_action_callbacks
actionpack (3.2.13) lib/abstract_controller/callbacks.rb : 17: trong `process_action '
actionpack (3.2.13) lib/action_controller/kim loại/rescue.rb: 29: trong` process_action'
actionpack (3.2.13) lib/action_controller/kim loại/thiết bị đo đạc .rb: 30: trong `block in process_action '
activesupp ort (3.2.13) lib/active_support/notifications.rb: 123: trong `block in instrument '
activesupport (3.2.13) lib/active_support/notifications/instrumenter.rb: 20: in` instrument'
activesupport (3.2.13) lib/active_support/notifications.rb: 123: trong `cụ '
actionpack (3.2.13) lib/action_controller/kim loại/instrumentation.rb: 29: trong` process_action'
actionpack (3.2.13) lib/action_controller/kim loại/params_wrapper.rb: 207: trong `process_action '
actionpack (3.2.13) lib/abstract_controller/base.rb: 121: trong `quá trình
actionpack (3.2.13) lib/abstract_controller/rendering.rb: 45: trong` quá trình
actionpack (3.2.13) lib/action_controller/metal.rb: 203: trong `văn '
actionpack (3.2.13) lib/action_controller/kim loại/rack_delegation.rb: 14: trong` văn'
actionpack (3.2.13) lib/action_controller/metal.rb: 246: trong `block in action '
actionpack (3.2.13) lib/action_dispatch/routing/route_set.rb: 73: trong `call '
actionpack (3.2.13) lib/action_dispatch/routing/route_set.rb: 73: in` dispatch'
actionpack (3.2.13) lib/action_dispatch/định tuyến/route_set.rb: 36: trong `gọi'
hành trình (1.0.4) lib/chuyến/router.rb: 68: trong` khối trong cuộc gọi '
hành trình (1.0.4) lib/chuyến/router.rb: 56: trong `từng'
hành trình (1.0.4) lib/chuyến/router rb: 56: trong `gọi '
actionpack (3.2.13) lib/action_dispatch/định tuyến/route_set.rb: 612: trong` gọi'
cai ngục (1.2.1) lib/cai/quản lý rb: 35: trong `khối trong cuộc gọi '
cai ngục (1.2.1) lib/cai/manager.rb: 34: trong` bắt'
cai ngục (1.2.1) lib/cai/quản lý .rb: 34: trong `call '
actionpack (3.2.13) lib/action_dispatch/middleware/best_standards_support.rb: 17: trong `gọi '
rack (1.4.5) lib/rack/etag.rb: 23: trong` gọi'
rack (1.4.5) lib/rack/conditionalget.rb: 25: trong `gọi '
actionpack (3.2.13) lib/action_dispatch/middleware/head.rb: 14: trong` gọi'
actionpack (3.2.13) lib/action_dispatch/middleware/params_parser. rb: 21: trong `call '
actionpack (3.2.13) lib/action_dispatch/middleware/flash.rb: 242: trong` call'
giá (1.4.5) lib/rack/session/abstract/id.rb: 210: trong `context '
giá (1.4.5) lib/rack/session/abstract/id.rb: 205 : trong `gọi '
actionpack (3.2.13) lib/action_dispatch/middleware/cookies.rb: 341: trong` gọi'
activerecord (3.2.13) lib/active_record/query_cache.rb: 64 : trong `call '
activerecord (3.2.13) lib/active_record/connection_adapters/abstract/connection_pool.rb: 479: trong` call'
actionpack (3.2.13) lib/action_dispatch/middleware/callbacks.rb: 28: trong `khối trong cuộc gọi'
activesupport (3.2.13) lib/active_support/callbacks.rb: 405: trong` chạy _177144612565476380_ gọi _4534346825225857812__callbacks'
activesupport (3.2.13) lib/active_support/callbacks.rb: 405: trong `__run_callback'
activesupport (3.2.13) lib/active_support/callbacks.rb: 385 : trong `_run_call_callbacks '
activesupport (3.2.13) lib/active_support/callbacks.rb: 81: trong `run_callbacks'
actionpack (3.2.13) lib/action_dispatch/middleware/callbacks.rb: 27: trong` gọi'
actionpack (3.2.13) lib/action_dispatch/middleware/reloader.rb: 65: trong `call '
actionpack (3.2.13) lib/action_dispatch/middleware/remote_ip.rb: 31: trong` call'
actionpack (3.2.13) lib/action_dispatch/middleware/debug_exceptions.rb: 16: trong `call '
actionpack (3.2.13) lib/action_dispatch/middleware/show_exceptions.rb: 56: trong `call '
railties (3.2.13) lib/rails/rack/logger.rb: 32: trong` call_app'
railties (3.2.13) lib/ray/rack/logger.rb: 16: trong `khối trong cuộc gọi'
activesupport (3.2.13) lib/active_support/tagged_logging.rb: 22: trong` tagged '
railties (3.2.13) lib/ray/rack/logger.rb: 16: trong `gọi'
actionpack (3.2.13) lib/action_dispatch/middleware/request_id.rb: 22: trong `gọi '
rack (1.4.5) lib/rack/methodoverride.rb: 21: trong` gọi'
rack (1.4. 5) lib/rack/runtime.rb: 17: trong `gọi '
activesupport (3.2.13) lib/active_support/cache/chiến lược/local_cache.rb: 72: trong` gọi'
rack (1.4.5) lib/rack/lock.rb: 15: trong `call '
actionpack (3.2.13) lib/action_dispatch/middleware/static.rb: 63: trong` call'
railties (3.2.13) lib/ray/engine.rb: 479: trong `gọi '
railties (3.2.13) lib/ray/application.rb: 223: trong` gọi'
railties (3.2.13) lib/ray/railtie/configurable.rb: 30: trong `method_missing '
hành khách (4.0.2) lib/phusion_passenger/rack/thread_handler_extension.rb: 77: trong` process_request'
hành khách (4.0.2) lib/phusion_passenger/request_handler/thread_handler.rb: 135: trong `accept_and_process_next_request '
hành khách (4.0.2) lib/phusion_passenger/request_handler/thread_handler.rb: 106: trong `main_loop'
hành khách (4.0.2) lib/phusion_passenger/request_handler.rb: 449: trong` khối (4 cấp độ) trong start_threads'
hành khách (4.0.2) lib/phusion_passenger/utils/robust_interruption.rb: 108: trong `disable_interruptions'
hành khách (4.0.2) lib/phusion_passenger/request_handler.rb: 444: in `block (3 levels) trong start_threads '
Chỉnh sửa: Đây là văn bản chạy Devise.helpers trong bảng điều khiển.
$ ray console
tải môi trường phát triển (Rails 3.2.13)
1.9.3-p429: 001> Devise.helpers
=> # < Set: {Vạch: : Bộ điều khiển :: Người trợ giúp}>
Chỉnh sửa: Đây là tệp rb tuyến đường của tôi. : Application.routes.draw do
devise_for :users
resource :sessions, :only => [:new, :create, :destroy]
devise_scope :user do
match 'signup' => 'users#new', :as => :signup
match 'register' => 'users#create', :as => :register
match '/login' => 'sessions#new', :as => :login
match 'logout' => 'sessions#destroy', :as => :logout
end
match '/activate/:activation_code' => 'users#activate', :as => :activate, :activation_code => nil
match '/users/:id', :to => 'users#show', :as => :user
resources :users do
member do
put :suspend
put :unsuspend
delete :purge
end
end
resource :sessions
other resources
match '' => 'home#index', :as => :home
match ':controller(/:action(/:id))'
root to: 'home#index'
end
@Btuman, thử thử nghiệm với devise_for trong routes.rb có lẽ có lỗi trong vấn đề thiết lập tuyến đường/không gian tên. Hãy thử 'rake routes' để xem chúng có được thiết lập đúng hay không.Tôi đã có một vấn đề như thế trước đây và nó liên quan trực tiếp đến các đường xấu thiết lập –
@RickCigarette, tại sao người giúp đỡ bị ảnh hưởng bởi một tuyến đường xấu? – Btuman