views:

21

answers:

1

Hi

I'm relatively new to Ruby on Rails 3 and hope to integrate Ambethia's Recaptcha plugin into my app.

In following what looks like Rails 2 documentation, it's asked to place the following into environment.rb

ENV['RECAPTCHA_PUBLIC_KEY']  = '6Lc6BAAAAAAAAChqRbQZcn_yyyyyyyyyyyyyyyyy'
ENV['RECAPTCHA_PRIVATE_KEY'] = '6Lc6BAAAAAAAAKN3DRm6VA_xxxxxxxxxxxxxxxxx'

Where exactly does this go in relation to the Rails 3 environment.rb file, which currently looks like the following:

# Load the rails application
require File.expand_path('../application', __FILE__)

# Initialize the rails application
Testapp::Application.initialize!
+1  A: 

in rails 3, you can use your Rails::Application class like a singleton so, you can add directly

module TestApp
 class Application < Rails::Application
    config.recaptcha_public_key = 'XXX'
    config.recaptcha_private_key = 'XXX'
 end
end

And after you can access to this data by

TestApp::Application.config.recaptcha_public_key
TestApp::Application.config.recaptcha_private_key

No more needed you ENV data.

In your controller a simple line works.

verify_recaptcha(:private_key => TestApp::Application.config.recaptcha_private_key)

And in view

<%= recaptcha_tags :public_key => TestApp::Application.config.recaptcha_public_key %>
shingara