I am getting a uninitialized constant Project::Controller. I've looked through the Rails docs and posts here on SO, but the code seems to be setup correctly. I am using rails 5.1.1. My pages path works fine, only the root path gives the error.
routes .rb
Rails.application.routes.draw do
devise_for :admin_users, ActiveAdmin::Devise.config
ActiveAdmin.routes(self)
devise_for :users,
path: '',
path_names: {
sign_in: 'login',
sign_out: 'logout',
edit: 'profile'
},
controllers: { omniauth_callbacks: 'omniauth_callbacks' }
get 'pages/about'
root 'project/#index'
resources :project do
resources :task, only: [:show]
end
end
project_controller.rb
class ProjectController < ApplicationController
def index
#projects = Project.all
end
def show
#project = Project.find(params[:id])
#tasks = #project.tasks
end
end
Change
root 'project/#index'
to
root 'project#index'
Related
I'm overriding Devise controllers in Rails like that:
module Api
module V1
module Devise
class RegistrationsController < Devise::RegistrationsController
....
end
end
end
end
And thats my routes:
Rails.application.routes.draw do
root 'application#index'
devise_for :users
devise_for :taxi_drivers, only: :passwords
resources :taxi_drivers_groups, only: %i[index new create edit update]
namespace :api do
namespace :v1 do
devise_for :users,
defaults: { format: :json },
class_name: 'User',
skip: %i[registrations sessions passwords],
path: '',
path_names: { sign_in: 'login', sign_out: 'logout' }
devise_scope :user do
post 'signup', to: 'devise/registrations#create'
post 'login', to:'devise/sessions#create'
delete 'logout', to: 'devise/sessions#destroy'
post 'password_recover', to: 'devise/passwords#create'
put 'password_recover', to: 'devise/passwords#update'
end
end
end
end
And I'm getting an error when I try to pass my tests:
ActionController::RoutingError: uninitialized constant Api::V1::Devise::RegistrationsController
And in my test file:
test 'user invalid sigup with empty fields' do
#valid_signup_params[:name] = nil
post('/api/v1/signup.json', { user: #valid_signup_params }, headers: { format: :json })
assert_equal last_response.status, 422
assert_equal json_response['errors']['name'].count, 1
end
Do you have any idea how to fix this error?
Thanks!
The issues comes from a constant clash between the newly defined controller and the existing one.
Replacing class RegistrationsController < Devise::RegistrationsController with class RegistrationsController < ::Devise::RegistrationsController is fixing the issue as ruby knows that he has to find the RegistrationsController class in the previously defined Devise module and not in the current definition.
i updated the app i am working with with ruby 3.1.2, and rails 7.0.3.1, before everything worked but now i get this error, which i believe is due to the file created for active_admin.
this is the active_admin file
class ActiveAdmin::Devise::SessionsController
include ::ActiveAdmin::Devise::Controller
def create
super
resource.login_histories.create(ip: request.remote_ip)
end
end
the routes
Rails.application.routes.draw do
devise_for :admin_users, ActiveAdmin::Devise.config
ActiveAdmin.routes(self)
devise_for :users, controllers: { registrations: 'users/registrations', sessions: 'users/sessions' }
devise_scope :user do
root 'users/sessions#new'
end
end
Here is the SessionsController
class Users::SessionsController < Devise::SessionsController
def new
super
end
def create
super
resource.login_histories.create(ip: request.remote_ip)
end
end
I am a beginner any help will be appreciated. thank you.
Mik.
I'm having trouble with controllers and routes in ruby on rails. I cant figure out what i've done wrong. I appreciate help! I guess its a pleural issue however i'm only a begginer.
Errors says Routing error | uninitialized constant App::SettingsController
Controller:
class App::SettingsController < App::BaseController
def index
end
end
Routes:
Rails.application.routes.draw do
get 'calendar/index'
root to: 'visitors#index'
devise_for :users, controllers: {
sessions: 'users/sessions',
registrations: 'users/registrations',
passwords: 'users/passwords',
invitations: 'users/invitations',
}
namespace :app do
get 'dashboard' => 'dashboards#index', as: :dashboards
get 'setting' => 'settings#index', as: :settings
get 'report' => 'reports#index', as: :reports
resources :residents
resources :contacts
resources :users do
collection do
get :profile
end
end
end
namespace :admin do
resources :users
end
end
View:
app/views/app/settings
app/views/app/settings/index.html.erb
Wrong file name setting.rb should be settings_controller.rb
I have following setup in routes.rb:
devise_for :users, path_names: { sign_in: "login", sign_out: "logout" },
controllers: { omniauth_callbacks: "authentications", registrations: "users/registrations", :sessions => "users/sessions" }
devise_scope :user do
... some other routes ...
end
When I try to sign up, log in or log out, I always get a similar error message like this:
Routing Error
uninitialized constant Users::SessionsController
In controllers, I have a folder called users and in this folder is registrations_controller.rb with following content:
class Users::RegistrationsController < Devise::RegistrationsController
def create
super
session[:omniauth] = nil unless #user.new_record?
end
def build_resource(*args)
super
if session[:omniauth]
#user.apply_omniauth(session[:omniauth])
#user.valid?
end
end
end
How to get rid of that error message?
Thank you.
I am using Devise 3.1.1 and am trying to redirect user to the Sign In page after he signs up.
As instructed in Devise's wiki I overridden RegistrationsController with the following:
class RegistrationsController < Devise::RegistrationsController
protected
def after_inactive_sign_up_path_for(resource)
'/users/sign_in'
end
end
As instructed, I also added the following line to the routes.rb:
devise_for :users, controllers: { registrations: 'registrations'}
After which I get the following error when I go to sign in page:
Invalid route name, already in use: 'new_user_session' You may have defined two routes with the same name using the:asoption, or you may be overriding a route already defined by a resource with the same naming.
In my routes I already have this defined:
devise_for :users, skip: :registrations
devise_scope :user do
resource :registration,
# disabled :edit & :destroy
only: [:new, :create, :update],
path: 'users',
path_names: { new: 'sign_up' },
controller: 'devise/registrations',
as: :user_registration do
get :cancel
end
end
You can only define the devise_for block once, and as you're already messing with the default registrations controller you should be able to just do something like the following to have devise use your controller:
devise_for :users, skip: :registrations
devise_scope :user do
resource :registration,
# disabled :edit & :destroy
only: [:new, :create, :update],
path: 'users',
path_names: { new: 'sign_up' },
controller: 'registrations',
as: :user_registration do
get :cancel
end
end