【发布时间】:2011-05-28 23:31:13
【问题描述】:
我已经尝试过做的事情:我尝试阅读 github 上的文档并让它在 Rubymine 上运行,我设法将自己与控制器所需的东西以及在配置文件夹。我试过谷歌,发现了一些很好的教程,但是他们缺少的步骤我不一定知道要跳。
我想弄清楚的是:我希望能够在登录注册中使用 recaptcha,利用 devise gem,我已经为我的 devise 登录生成了页面。
到目前为止我所拥有的:
我已经安装并附加了:devise 1.2.rc 和 recaptcha 0.3.1 我在 windows xp 上运行 Rubymine。 Ruby SDK 1.8.7-p302,带有 Rails 3.0.3
我去过谷歌并拥有我的公钥和私钥 下一步告诉我应该将我的密钥添加到 project/config/initializers/recaptcha.rb 这是该文件中包含的内容:
Recaptcha.configure do |config|
config.public_key = 'myKey'
config.private_key = 'myKey'
end
现在我应该用以下方法修复我的 gemfile:
gem 'recaptcha', :require => 'recaptcha/rails'
我还有我的 config/application.rb 阅读:
require 'rails/all'
require 'net/http'
我还在 External Libraries/[gem] devise/app/views/devise/registrations/new.html.erb 中添加了 recaptcha 标记:
<%= recaptcha_tags %>
<p><%= f.submit "Sign up" %></p>
我遇到问题的地方(我认为)是 app/controllers/registrations_controller.rb 和 config/routes.rb
对于这些文件的具体内容,我有点不知所措。任何帮助将不胜感激,或者有人编写的指导我逐步完成此操作的教程将非常有帮助。谢谢
这是我在菲利克斯发帖后所做的:
外部库/app/controllers/devise/registrations_controller.rb
类设计::注册控制器
if verify_recaptcha then
super
else
build_resource
clean_up_passwords(resource)
flash[:notice] = 'Invalid Captcha'
render_with_scope :new
end
build_resource
if resource.save
if resource.active?
set_flash_message :notice, :signed_up
sign_in_and_redirect(resource_name, resource)
else
set_flash_message :notice, :inactive_signed_up, :reason => resource.inactive_message.to_s
expire_session_data_after_sign_in!
redirect_to after_inactive_sign_up_path_for(resource)
end
else
clean_up_passwords(resource)
render_with_scope :new
end
end
来自 Project/config/routes.rb:
devise_for :users, :controllers => {:registrations => 'registrations'}
这是它吐出的错误:
ActionController::RoutingError(未初始化的常量 RegistrationsController):
在救援/布局 (0.0ms) 内渲染 C:/Ruby/lib/ruby/gems/1.8/gems/actionpack-3.0.3/lib/action_dispatch/middleware/templates/rescues/routing_error.erb .... 。 有任何想法吗?
【问题讨论】:
标签: ruby-on-rails-3