在尝试在我的 Ruby on Rails 站点上安装“Restful-Authentication”插件后,我遇到了一些问题。
我对 Ruby on Rails 和一般编程仍然很陌生,所以我可能忘记了一些东西,也许。
我正在运行 Ruby 1.9.3p125 和 Rails 3.2.1
浏览注册页面时,我收到以下错误消息:
uninitialized constant User::Authentication
然后,如果我刷新页面,我会收到其他错误消息:
undefined method `key?' for nil:NilClass
完整跟踪:
actionpack (3.2.1) lib/action_controller/metal/hide_actions.rb:36:in `visible_action?'
actionpack (3.2.1) lib/action_controller/metal/hide_actions.rb:18:in `method_for_action'
actionpack (3.2.1) lib/action_controller/metal/implicit_render.rb:14:in `method_for_action'
actionpack (3.2.1) lib/action_controller/metal/compatibility.rb:61:in `method_for_action'
actionpack (3.2.1) lib/abstract_controller/base.rb:115:in `process'
actionpack (3.2.1) lib/abstract_controller/rendering.rb:45:in `process'
actionpack (3.2.1) lib/action_controller/metal.rb:203:in `dispatch'
actionpack (3.2.1) lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
actionpack (3.2.1) lib/action_controller/metal.rb:246:in `block in action'
actionpack (3.2.1) lib/action_dispatch/routing/route_set.rb:66:in `call'
actionpack (3.2.1) lib/action_dispatch/routing/route_set.rb:66:in `dispatch'
actionpack (3.2.1) lib/action_dispatch/routing/route_set.rb:30:in `call'
journey (1.0.4) lib/journey/router.rb:68:in `block in call'
journey (1.0.4) lib/journey/router.rb:56:in `each'
journey (1.0.4) lib/journey/router.rb:56:in `call'
actionpack (3.2.1) lib/action_dispatch/routing/route_set.rb:589:in `call'
actionpack (3.2.1) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
rack (1.4.1) lib/rack/etag.rb:23:in `call'
rack (1.4.1) lib/rack/conditionalget.rb:25:in `call'
actionpack (3.2.1) lib/action_dispatch/middleware/head.rb:14:in `call'
actionpack (3.2.1) lib/action_dispatch/middleware/params_parser.rb:21:in `call'
actionpack (3.2.1) lib/action_dispatch/middleware/flash.rb:242:in `call'
rack (1.4.1) lib/rack/session/abstract/id.rb:205:in `context'
rack (1.4.1) lib/rack/session/abstract/id.rb:200:in `call'
actionpack (3.2.1) lib/action_dispatch/middleware/cookies.rb:338:in `call'
activerecord (3.2.1) lib/active_record/query_cache.rb:64:in `call'
activerecord (3.2.1) lib/active_record/connection_adapters/abstract/connection_pool.rb:443:in `call'
actionpack (3.2.1) lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
activesupport (3.2.1) lib/active_support/callbacks.rb:405:in `_run__960052277__call__392212310__callbacks'
activesupport (3.2.1) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.1) lib/active_support/callbacks.rb:385:in `_run_call_callbacks'
activesupport (3.2.1) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.2.1) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (3.2.1) lib/action_dispatch/middleware/reloader.rb:65:in `call'
actionpack (3.2.1) lib/action_dispatch/middleware/remote_ip.rb:31:in `call'
actionpack (3.2.1) lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call'
actionpack (3.2.1) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
railties (3.2.1) lib/rails/rack/logger.rb:26:in `call_app'
railties (3.2.1) lib/rails/rack/logger.rb:16:in `call'
actionpack (3.2.1) lib/action_dispatch/middleware/request_id.rb:22:in `call'
rack (1.4.1) lib/rack/methodoverride.rb:21:in `call'
rack (1.4.1) lib/rack/runtime.rb:17:in `call'
activesupport (3.2.1) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
rack (1.4.1) lib/rack/lock.rb:15:in `call'
actionpack (3.2.1) lib/action_dispatch/middleware/static.rb:53:in `call'
railties (3.2.1) lib/rails/engine.rb:479:in `call'
railties (3.2.1) lib/rails/application.rb:220:in `call'
rack (1.4.1) lib/rack/content_length.rb:14:in `call'
railties (3.2.1) lib/rails/rack/log_tailer.rb:14:in `call'
rack (1.4.1) lib/rack/handler/webrick.rb:59:in `service'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/webrick/httpserver.rb:138:in `service'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/webrick/httpserver.rb:94:in `run'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/webrick/server.rb:191:in `block in start_thread'
应用程序/控制器/users_controller.rb
class UsersController < ApplicationController
# Be sure to include AuthenticationSystem in Application Controller instead
include AuthenticatedSystem
# render new.rhtml
def new
@user = User.new
end
def create
logout_keeping_session!
@user = User.new(params[:user])
success = @user && @user.save
if success && @user.errors.empty?
redirect_back_or_default('/', :notice => "Thanks for signing up! We're sending you an email with your activation code.")
else
flash.now[:error] = "We couldn't set up that account, sorry. Please try again, or contact an admin (link is above)."
render :action => 'new'
end
end
def activate
logout_keeping_session!
user = User.find_by_activation_code(params[:activation_code]) unless params[:activation_code].blank?
case
when (!params[:activation_code].blank?) && user && !user.active?
user.activate!
redirect_to '/login', :notice => "Signup complete! Please sign in to continue."
when params[:activation_code].blank?
redirect_back_or_default('/', :flash => { :error => "The activation code was missing. Please follow the URL from your email." })
else
redirect_back_or_default('/', :flash => { :error => "We couldn't find a user with that activation code -- check your email? Or maybe you've already activated -- try signing in." })
end
end
def forgot
if request.post?
user = User.find_by_email(params[:user][:email])
respond_to do |format|
if user
user.create_reset_code
flash[:notice] = "Reset code sent to #{user.email}"
format.html { redirect_to login_path }
format.xml { render :xml => user.email, :status => :created }
else
flash[:error] = "#{params[:user][:email]} does not exist in system"
format.html { redirect_to login_path }
format.xml { render :xml => user.email, :status => :unprocessable_entity }
end
end
end
end
def reset
@user = User.find_by_reset_code(params[:reset_code]) unless params[:reset_code].nil?
if request.post?
if @user.update_attributes(:password => params[:user][:password], :password_confirmation => params[:user][:password_confirmation])
self.current_user = @user
@user.delete_reset_code
flash[:notice] = "Password reset successfully for #{@user.email}"
redirect_to root_url
else
render :action => :reset
end
end
end
end
应用程序/视图/用户/new.html.erb
<h1>Sign up as a new user</h1>
<% @user.password = @user.password_confirmation = nil %>
<%= error_messages_for :user %>
<%= form_for :user, :url => users_path do |f| -%>
<p><%= label_tag 'login' %><br/>
<%= f.text_field :login %></p>
<p><%= label_tag 'email' %><br/>
<%= f.text_field :email %></p>
<p><%= label_tag 'password' %><br/>
<%= f.password_field :password %></p>
<p><%= label_tag 'password_confirmation', 'Confirm Password' %><br/>
<%= f.password_field :password_confirmation %></p>
<p><%= submit_tag 'Sign up' %></p>
<% end -%>
配置/路由.rb
Blog::Application.routes.draw do
resources :users
resource :session, :only => [:new, :create, :destroy]
match 'signup' => 'users#new', :as => :signup
match 'register' => 'users#create', :as => :register
match 'login' => 'sessions#new', :as => :login
match 'logout' => 'sessions#destroy', :as => :logout
match 'forgot', :controller => 'users', :action => 'forgot'
match 'reset/:reset_code', :controller => 'users', :action => 'reset'
match '/activate/:activation_code' => 'users#activate', :as => :activate, :activation_code => nil
resources :posts do
resources :comments
end
(...)
如果您需要更多文件,请告诉我。谢谢!