使用rubymine 3.1安装带有现有设计宝石的recaptcha gem

时间:2011-05-28 23:31:13

标签: ruby-on-rails-3

我已经尝试过了:我已经尝试在github上阅读文档并将其用于Rubymine并且我设法将自己与控制器所需的内容混淆,并且需要在配置文件夹。我试过谷歌,发现了一些相当不错的教程,但他们缺少的步骤,我不一定知道跳过。

我想弄清楚:我希望能够在登录注册中使用recaptcha来完成设计宝石,我已经为我的设计登录生成了页面。

到目前为止我所拥有的:

我已经安装并附加:设计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'

我还添加到外部库/ [gem]设计/ app / views / devise / registrations / new.html.erb 重新标记:

   <%= recaptcha_tags %>
   <p><%= f.submit "Sign up" %></p>

我遇到的问题(我认为)是 app / controllers / registrations_controller.rb config / routes.rb

我对这些文件到底有什么不知所措。任何帮助将不胜感激,或者某人编写的教程将逐步引导我完成这将非常有帮助。感谢

以下是我在菲利克斯的帖子后所做的事情:

外部库/ app / controllers / devise / registrations_controller.rb

class Devise :: RegistrationsController&lt;设计:: RegistrationsController         def create

      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 .... 。 有任何想法吗?

1 个答案:

答案 0 :(得分:1)

对于您的路线,除了指定自定义控制器外,您可以保留正常的设计路线:

devise_for :users, :controllers => {:registrations => 'registrations'}

在registrations_controller.rb中,您想要继承Devise RegistrationsController并覆盖'create'方法:

class RegistrationsController < Devise::RegistrationsController
    def create
        if verify_recaptcha then
            super
        else
            build_resource
            clean_up_passwords(resource)
            flash[:notice] = 'Invalid Captcha'
            render_with_scope :new
        end
    end
end