0

Rails is not liking my namespacing -- even though I think I'm adhering to convention. Help?

I'm uing simple_form to create an admin form, and on submission, I get the error:

uninitialized constant Admins

My AdminsController looks as such:

class AdminsController < ApplicationController
  skip_before_action :authenticate_user!
  def index 
    @admins = Admin.all
  end

  def new
    @admin = Admin.new
  end

  def show
    @admin = Admin.find(params[:id])
  end

  def create

  end

  private 

  def admin_params
   params.require(:admin).permit(:username, :email, :password)
  end
end

My Admin Model --

class Admin < ActiveRecord::Base
  devise :database_authenticatable, :registerable,
     :recoverable, :rememberable, :trackable, :validatable
end

my form is kosher -- the view looks like:

<%= simple_form_for @admin do |f| %>
  <%= f.input :username, label: 'New Admin user name' %>
  <%= f.input :password, hint: 'No special characters. At leats 8 characters long.' %>
  <%= f.input :email, placeholder: 'admin@domain.com' %>
  <%= f.button :submit %>
<% end %>

And it gets rendered with the correct path noted in the html:

<form accept-charset="UTF-8" action="/admins" class="simple_form new_admin" id="new_admin" method="post" novalidate="novalidate">

Aaaaaand this lines up with the route I want, double checked with rake routes:

ruby POST /admins(.:format) admins#create

Yet when I submit -- the route is not mapped, and rails can't find my controller constant. I realize my create action is blank - but thats not my issue just now.

I'm sure this is simple and I'm overlooking something small. Let me know! Thanks

And thanks for asking -- the full back trace:

Completed 200 OK in 756ms (Views: 752.7ms | ActiveRecord: 0.5ms)


Started POST "/admins" for 127.0.0.1 at 2015-02-02 22:47:16 -0500

ActionController::RoutingError (uninitialized constant Admins):

activesupport (4.1.5) lib/active_support/inflector/methods.rb:238:in `const_get'
activesupport (4.1.5) lib/active_support/inflector/methods.rb:238:in `block in constantize'
activesupport (4.1.5) lib/active_support/inflector/methods.rb:236:in `each'
activesupport (4.1.5) lib/active_support/inflector/methods.rb:236:in `inject'
activesupport (4.1.5) lib/active_support/inflector/methods.rb:236:in `constantize'
actionpack (4.1.5) lib/action_dispatch/routing/route_set.rb:78:in `controller_reference'
actionpack (4.1.5) lib/action_dispatch/routing/route_set.rb:68:in `controller'
actionpack (4.1.5) lib/action_dispatch/routing/route_set.rb:46:in `call'
actionpack (4.1.5) lib/action_dispatch/routing/mapper.rb:45:in `call'
actionpack (4.1.5) lib/action_dispatch/journey/router.rb:71:in `block in call'
actionpack (4.1.5) lib/action_dispatch/journey/router.rb:59:in `each'
actionpack (4.1.5) lib/action_dispatch/journey/router.rb:59:in `call'
actionpack (4.1.5) lib/action_dispatch/routing/route_set.rb:678:in `call'
warden (1.2.3) lib/warden/manager.rb:35:in `block in call'
warden (1.2.3) lib/warden/manager.rb:34:in `catch'
warden (1.2.3) lib/warden/manager.rb:34:in `call'
rack (1.5.2) lib/rack/etag.rb:23:in `call'
rack (1.5.2) lib/rack/conditionalget.rb:35:in `call'
rack (1.5.2) lib/rack/head.rb:11:in `call'
actionpack (4.1.5) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
actionpack (4.1.5) lib/action_dispatch/middleware/flash.rb:254:in `call'
rack (1.5.2) lib/rack/session/abstract/id.rb:225:in `context'
rack (1.5.2) lib/rack/session/abstract/id.rb:220:in `call'
actionpack (4.1.5) lib/action_dispatch/middleware/cookies.rb:560:in `call'
activerecord (4.1.5) lib/active_record/query_cache.rb:36:in `call'
activerecord (4.1.5) lib/active_record/connection_adapters/abstract/connection_pool.rb:621:in `call'
activerecord (4.1.5) lib/active_record/migration.rb:380:in `call'
actionpack (4.1.5) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (4.1.5) lib/active_support/callbacks.rb:82:in `run_callbacks'
actionpack (4.1.5) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (4.1.5) lib/action_dispatch/middleware/reloader.rb:73:in `call'
actionpack (4.1.5) lib/action_dispatch/middleware/remote_ip.rb:76:in `call'
actionpack (4.1.5) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
actionpack (4.1.5) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.1.5) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.1.5) lib/rails/rack/logger.rb:20:in `block in call'
activesupport (4.1.5) lib/active_support/tagged_logging.rb:68:in `block in tagged'
activesupport (4.1.5) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (4.1.5) lib/active_support/tagged_logging.rb:68:in `tagged'
railties (4.1.5) lib/rails/rack/logger.rb:20:in `call'
actionpack (4.1.5) lib/action_dispatch/middleware/request_id.rb:21:in `call'
rack (1.5.2) lib/rack/methodoverride.rb:21:in `call'
rack (1.5.2) lib/rack/runtime.rb:17:in `call'
activesupport (4.1.5) lib/active_support/cache/strategy/local_cache_middleware.rb:26:in `call'
rack (1.5.2) lib/rack/lock.rb:17:in `call'
actionpack (4.1.5) lib/action_dispatch/middleware/static.rb:64:in `call'
rack (1.5.2) lib/rack/sendfile.rb:112:in `call'
railties (4.1.5) lib/rails/engine.rb:514:in `call'
railties (4.1.5) lib/rails/application.rb:144:in `call'
rack (1.5.2) lib/rack/lock.rb:17:in `call'
rack (1.5.2) lib/rack/content_length.rb:14:in `call'
rack (1.5.2) lib/rack/handler/webrick.rb:60:in `service'
/Users/AviFoxi/.rvm/rubies/ruby-2.0.0-p451/lib/ruby/2.0.0/webrick/httpserver.rb:138:in `service'
/Users/AviFoxi/.rvm/rubies/ruby-2.0.0-p451/lib/ruby/2.0.0/webrick/httpserver.rb:94:in `run'
/Users/AviFoxi/.rvm/rubies/ruby-2.0.0-p451/lib/ruby/2.0.0/webrick/server.rb:295:in `block in start_thread'

And as per request -- My config/routes.rb

Rails.application.routes.draw do

  devise_for :admins, controllers: { registrations: "admins/registrations" }
  devise_for :users


  root to: "users#index"

  resources :users
  resources :admins
  resources :ride_years
end
Avi Fox-Rosen
  • 55
  • 1
  • 6

1 Answers1

0

try changing

devise_for :admins, controllers: { registrations: "admins/registrations" }

to

devise_for :admins, controllers: { registrations: "admins_registrations" }

Lukasz Muzyka
  • 2,783
  • 1
  • 30
  • 41