Search code examples
ruby-on-railsrubyruby-on-rails-3ruby-on-rails-3.2ruby-on-rails-3.1

Ruby on Rails: uninitialized constant AdminController


I'm currently trying to set up an admin page. I'm creating a form in the page where I can update user's profile using checkboxes, but when I tried to submit, I get sent to a routing error page with uninitialized constant AdminController

my routes.rb

namespace :admin do 
  get '', to: 'dashboard#index', as: '/' 
end
resources :admin do
 collection  do
    post :edit_multiple
    put :update_multiple
  end
end

controllers/admin/dashboard_controller.rb

class Admin::DashboardController < ApplicationController
  def index
    @users = User.all
    @admin = User.new
  end

  def edit_multiple
  end

  def update_multiple
  end
end

views/admin/dashboard/index.html.erb

<%= form_tag edit_multiple_admin_index_path do |f| %>
<table>
  <% @users.each do |user| %>
  <% if !user.public %>
  <tr>  
    <td><%= check_box_tag "user_ids[]", user.id %></td>
  </tr>
  <% end %>
  <% end %>
</table>

<%= submit_tag "Edit Checked" %>
<% end %>

Anyone know when I'm getting this error?

Thanks!


Solution

  • Change your routes.rb file to:

    namespace :admin do 
      get '', to: 'dashboard#index', as: '/' 
      resource :dashboard do
        post :edit_multiple
        put :update_multiple
      end
    end