Closed eddielopezzzz closed 12 years ago
You should be able to override ContactUs::ContactsController. I would attempt to essentially just copy the controller file from the source code under app/controllers/contact_us/contacts_controller.rb
then drop that into your application at the same file path. You could then modify the create action to implement the recaptcha code.
Or yo could also attempt to make a contacts controller within your application that is a subclass of ContactUs::ContactsController and then override the create action. You would then need to modify your routes to use your contacts controller rather than the gems. This is usually a more desirable solution when trying to override an engines controller since it makes upgrading the gem easier.
I don't foresee any changes coming to the contact_us gem anytime soon unless I need to update the controller for a new version of Rails. So just attempting to override the controller directly in the first option should be fine, and probably easier to implement.
I installed the recaptcha gem in my Gemfile like so:
gem "recaptcha", :require => "recaptcha/rails"
I added the recaptcha tag in app/views/contact_us/contacts/new.html right before the submit tag
The captcha control renders successfully but I am stuck as to validate the captcha control. According to http://blog.ncodedevlabs.com/2010/01/26/implementing-recaptcha-in-your-rails-app/
To verify the captcha simple add verify_recaptcha() to your controller like the below:
if verify_recaptcha(:message => "Please enter the characters. Thank you") and @user.save redirect_to :action => “login” flash[:notice] = “Your account setup is almost complete please check your mail for activation link.” end
However, this contact_us script doesnt create controllers where I can add the verify_captcha() function. Any ideas as to how captcha can be implemented?