my Devise Recaptcha isn't working correctly because I can skip right over it and still register.
I followed the Devise wiki at - https://github.com/plataformatec/devise/wiki/How-To:-Use-Recaptcha-with-Devise and got everything working accept i encountered the problem above.
Here is my code:
app/controllers/users/registrations.rb
class Users::RegistrationsController < Devise::RegistrationsController
def create
if verify_recaptcha
super
else
build_resource
clean_up_passwords(resource)
flash[:alert] = "There was an error with the recaptcha code below. Please re-enter the code and click submit."
render_with_scope :new
end
end
end
routes.rb
YourApp::Application.routes.draw do
devise_for :users do
root :to => "devise/registrations#new"
get "/" => "devise/registrations#new"
post '/' => 'registrations#new', :as => :new_user_registration
match '/', :to => 'devise/registrations#new'
.
.
.
.
.
end
devise_for :users, :controllers => { :registrations => "users/registrations" }
namespace :user do
root :to => "home#index"
end
config/initializers/recaptcha.rb
Recaptcha.configure do |config|
config.public_key = 'mykey123456789'
config.private_key = 'mykey13456789'
end
It is possible it doesn't work because i am in test mode and not on my domain name?
Help would be appreciated!
In environment.rb put the following:
ENV['RECAPTCHA_PUBLIC_KEY'] = 'mykey123456789'
ENV['RECAPTCHA_PRIVATE_KEY'] = 'mykey123456789'
Not being on your domain name may be a problem depending on how you registered the keys.
This was an issue with not having ImageMagick or RMagick installed, had to go through the nonsense to get this working.
These were my trials & tribulations:
ImageMagick - "CORE_RL_magick_.dll not found" or how to install RMagick on windows with ruby 1.9.2
Related
I am testing ajax with devise and am running into this error in console:
GET https://example.com/users/get_company?foo=bar 404 (Not Found)
and rails server is returning:
ActionController::RoutingError (uninitialized constant UsersController):
A little bit of code:
config/routes.rb
devise_for :users, :controllers => {registrations: 'registrations'}
devise_scope :user do
authenticated :user do
root 'account#show', as: :authenticated_root
end
unauthenticated do
root 'devise/sessions#new', as: :unauthenticated_root
end
end
get 'users/get_company', as: 'get_company'
initializers/devise.rb
config.http_authenticatable_on_xhr = true
config.navigational_formats = ['*/*', :html]
controllers/registrations_controller.rb
class RegistrationsController < Devise::RegistrationsController
respond_to :json
def get_company
#company = Company.first.name
respond_to do |format|
format.js
end
end
end
In views/devise/registrations there is new.html.erb, get_company.js.coffee and in assets/javascripts there is get_company.js.coffee.
These seem to be working fine because the event happens and then I am getting the routing error.
Any help would be greatly appreciated as I am just learning this to help out with a project. Please ask for any additional code or anything that might help explain the situation better.
Hey your route of get_company is missing /, so it would be:
devise_for :users, :controllers => {registrations: 'registrations'}
devise_scope :user do
authenticated :user do
root 'account#show', as: :authenticated_root
end
unauthenticated do
root 'devise/sessions#new', as: :unauthenticated_root
end
# 1: If you put your get_company route here, it still works
get '/users/get_company' => 'registrations#get_company', as: 'get_company'
end
# 2: If you put your get_company route here, it works as well
# get '/users/get_company' => 'registrations#get_company', as: 'get_company'
You code will work fine either you put the route in position #1 or #2
I have started on a web application for user registration etc. using devise gem. I am novice to Ruby/Rails env. So this is part of my training.
My question is very similar to an old posting # devise overriding registrations controller - uninitialized constant Users::RegistrationsController
After the homepage displays, when I click on signup button, I get this error. I have done some research on this issue on the web to no avail.
In app/controllers/users/registrations_controllers.rb I have this code:
class Users::RegistrationsController < Device::RegistrationsController
def create
super do |resource|
if params[:plan]
resource.plan_id = params[:plan]
if resource.plan_id == 2
resource.save_with_payment
else
resource.save
end
end
end
end
end
In Routes.rb I have this line of code:
devise_for :users, :controllers => { :registrations => 'users/registrations' }
Please let me know if you need any other information to help resolve this error.
In routes.rb, try:
devise_for :users,
:skip => [:registrations, :sessions]
as user do
# Registrations
get '/signup' => 'users/registrations#new', as: :new_user_registration
post '/signup' => 'users/registrations#create', as: :user_registration
It should work.
In my app I have two devise models admin and user.
My rails_admin.rb
RailsAdmin.config do |config|
config.main_app_name = ['MyApp', 'Admin']
config.current_user_method { current_admin } # auto-generated
config.authenticate_with {} # leave it to authorize
config.authorize_with do
redirect_to main_app.new_admin_session_path unless current_admin
end
end
And in my routes.rb
devise_for :admins
mount RailsAdmin::Engine => '/admin', :as => 'rails_admin'
devise_for :users
When I access /admin the app redirects me to /users/sign_in
What is wrong, why I am not redirected to /admins/sign_in?
I had the same issue.
I have fixed it after making some changes into routes.rb
can you please try the same and let me know, if that helps you.
devise_for :admins
mount RailsAdmin::Engine => '/admins', :as => 'rails_admin'
devise_for :users
Examples are here.
http://madhulata.in/admins
and
http://madhulata.in
I'm trying to add a custom action to Devise's registration controller which allows users to change their passwords (I cannot use default registrations#edit since I need a form for changing only password, not email/username). The implementation I wrote below works in development mode but I get this error when I test controller.
Failure/Error: get 'password'
ActionController::RoutingError:
No route matches {:controller=>"registrations", :action=>"password"}
There is my code (I tried to skip unrelated parts)
spec/controllers/registrations_controller_spec.rb
describe RegistrationsController do
include Devise::TestHelpers
before :each do
request.env["devise.mapping"] = Devise.mappings[:users]
end
describe "GET 'password'" do
it "..." do
# The problem is here,
get 'password' # it raises ActionController::RoutingError
end
end
end
app/controllers/registrations_controller.rb
class RegistrationsController < Devise::RegistrationsController
# ...
def password
end
end
config/routes.rb
devise_for :users, path: 'account',
controllers: { registrations: 'registartions' },
skip: [:registartions, :sessions]
devise_scope :user do
# ...
scope '/account' do
get 'password' => 'devise/registartions#password', as: "change_password
do
end
spec_helper.rb
# ...
RSpec.configure do |config|
# ...
config.include Devise::TestHelpers, :type => :controller
end
I would usually add a comment for this, but I'm including a code block and it gets messy in comments.
It seems like you're trying to preform a GET on /password instead of on /account/password.
From what I'm reading, you've got a mapping for /account/password:
devise_scope :user do # used to remove /users/ part from devise URLs
# ...
scope '/account' do # adds /account to URLs
get 'password' => 'devise/registartions#password', as: "change_password"
# this will match /account/passwordAnswer
do
end
So you should either remove the scope, or replace your get request in test with this:
get "/account/password", :user => #user
or this
get change_password_path(#user)
Where #user is a User's mock.
Run rake routes to confirm.
Have you set up your config/routes.rb with the following.
devise_for :users do
get 'logout' => 'devise/sessions#destroy'
get 'changepassword' => 'devise/registrations#edit'
get 'access' => 'homepages#access'
get 'history' => 'policies#history'
get 'future' => 'policies#future'
end
devise_for :users, :controllers => { :sessions => :sessions }
resources :users
I have the same problem. I set the routes then it was worked for me :)
I don't like using get "/account/password" or a path in my spec. Seems hacky. I fixed a similar problem by using better syntax in my routes.rb file:
Using path: 'account' option in devise_for
Explicitly setting my custom controller with controllers: {registrations: 'registrations'}
So my routes.rb looks like this:
devise_for :users,
path: 'account',
path_names: {sign_in: 'login', sign_out: 'logout', sign_up: 'register'},
controllers: {registrations: 'registrations'},
skip: [:passwords]
Then I can use get :new in my test. Much cleaner.
Hope this helps someone else.
I am using devise 3.0.
When I login on my page I automatic go to the route: http://localhost:3000/sessions/user
And I get this error:
Routing Error
No route matches "/sessions/user"
I have created a controller named sessions_controller.rb in users folder here it is:
class Users::SessionsController < Devise::SessionsController
def new
redirect_to root_url, :notice => "You have been logged out."
end
def create
user = User.authenticate(params[:login], params[:encrypted_password])
if user
session[:user_id] = user.id
redirect_to root_url, :notice => "Logged in successfully."
else
flash.now[:alert] = "Invalid login or password."
render :action => 'new'
end
end
def destroy
session[:user_id] = nil
redirect_to root_url, :notice => "You have been logged out."
end
end
My route file:
Densidste::Application.routes.draw do
match 'user/edit' => 'users#edit', :as => :edit_current_user
devise_for :users, :controllers => { :sessions => "users/sessions" } do
get "login", :to => "devise/sessions#new"
get "opret", :to => 'users/users#new'
get "logud", :to => 'users/users#destroy'
end
resources :sessions
resources :users
devise_for :users, :controllers => { :sessions => "users/sessions" }
resources :aktivs
resources :taggingposts
resources :tags
resources :kommentares
resources :posts
end
(Old question but I ran into the same issue when setting up Devise, so hope this helps others)
Removing resources :sessions from the routes file should solve the problem.
For those who experiencing this issue with Devise 2.0 and Rails 3.2.1 and checked all the observations made by #Micah Alcorn but still facing the problem — restart your web server. Worked for me.
You don't have a root_url defined. It is still pointing to the static public/index.html. (edited out by Ryan Bigg)
devise_for :users is stated twice.
resources :users is unnecessary unless you have a RESTful controller handling destroy and index actions outside of devise.
Do you, in fact, have a "users" controller for that first edit action too? That should probably be in a custom Users::RegistrationsController < Devise::RegistrationsController.