-
Notifications
You must be signed in to change notification settings - Fork 0
Using with Rails 4 and Devise
This wiki document describes the way to use is_bot with Devise and Rails 4. With Rails 4, a list of legitimate parameters need to be listed in the controller. As a result, we need to allow the captcha_in_reverse as a permitted field to the devise controller. Here's how you do it for sign up form in devise. captcha_in_reverse is the field added to your form to catch out any bots when you use is_bot gem.
- You know HAML.
- You also know how to extend devise default views/controllers.
## Steps
Create a registrations_controller like the one below
class RegistrationsController < Devise::RegistrationsController
before_filter :configure_permitted_parameters
private
def configure_permitted_parameters
devise_parameter_sanitizer.for(:sign_up).push(:captcha_in_reverse)
end
end
If you already have a registrations_controller, just add the following lines to it then:
before_filter :configure_permitted_parameters
private
def configure_permitted_parameters
devise_parameter_sanitizer.for(:sign_up).push(:captcha_in_reverse)
end
Add the following line to your routes file to inform devise of the custom registrations controller:
devise_for :users, controllers: {
registrations: "registrations"
}
Add the following line to your user model:
class User < ActiveRecord::Base
// Other code
validate_captcha
// Other methods
end
Finally, add the following line to your view file, most typically at app/views/devise/registrations/new.html.haml. This line should be added with rest of the field
definitions:
= f.input :email
= f.input :password
= captcha_reverse_field resource.class.to_s.downcase
resource.class.to_s.downcase will be evaluated to :user in this case.