2011-05-28 45 views
1

我已經嘗試過的做法:我已經嘗試閱讀github上的文檔並使其在Rubymine上工作,並且我已經設法將自己與需要的內容混淆在一起至於控制器,以及config文件夾中需要什麼。我試過谷歌,發現了一些很不錯的教程,但他們缺少的步驟,我不一定知道跳也。安裝與現有設計寶石與rubymine的recaptcha gem 3.1

我想弄清楚的是:我希望能夠在登錄註冊中使用recaptcha,使用設計寶石,我已經爲我的設計登錄生成了頁面。

我有什麼至今:

我已經安裝和連接:制定1.2.rc和驗證碼0.3.1我在Windows XP上運行的RubyMine。 Ruby SDK 1.8.7-p302,使用Rails 3.0.3

我去過谷歌並使用我的公鑰和私鑰 下一步告訴我我應該添加我的密鑰到project/config /初始化/ 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' 

我也加入到我的外部庫/ [寶石]設計/應用/視圖/設計/註冊/ new.html.erb的ReCaptcha標籤:

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

當我遇到問題,(我認爲)是 應用程序/控制器/ registrations_controller.rb的config/routes.rb中

我對這些文件到底有什麼不知所措。任何幫助將不勝感激,或者有人寫過的教程一步一步地引導我完成這一任務將會非常有幫助。由於

這裏是我能在時隔Felix的崗位做:

外部庫/應用/控制器/設計/ registrations_controller.rb

類設計:: RegistrationsController <設計:: RegistrationsController 高清創建

 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):

渲染C:/Ruby/lib/ruby/gems/1.8 /resms/actionpack-3.0.3/lib/action_dispatch/middleware/templates/rescues/routing_error.erb內救援/佈局(0.0ms).....有什麼想法?

回答

1

爲了您的路線,你可以保持您正常的色器件的路線,除了指定您的自定義控制器:

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

在registrations_controller.rb,要繼承的設計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 
+0

所以在我的registrations_controller.rb我有我當前的def創建...我要完全替換或添加到? – Matt 2011-05-29 04:02:45

+0

那麼,您當前的註冊控制器應該繼承Devise註冊控制器並且除非您已經進行了其他自定義,否則應該是空的。如果你已經定義了一個create方法,你只需要在'verify_recaptcha'返回false時停止註冊過程。 – Felix 2011-05-29 04:18:01