6

i have a simple cms on ROR 3.2. with this folder scheme:

app |controllers |my controllers

but i wanted to have an "admin" section where i could have some controllers too. so i created

rails generate controller admin/Users

app | controllers |admin & my admin controllers

so my file is:

users_controller.rb
class Admin::UsersController < ApplicationController

  def index
    render(:text => "sou o index!")
  end

  def list
    render(:text => "sou o list")
  end

end

On my routes i have:

namespace :admin do
    resources :users
  end

match ':controller(/:action(/:id))(.:format)'

Im new to rails and i cant figure out the solution. Cant find it anywhere.

The PROBLEM is i try do acess:

http://localhost:3000/admin/users/list

and i get this error:

Unknown action The action 'show' could not be found for Admin::UsersController

Simone Carletti
  • 173,507
  • 49
  • 363
  • 364
Miguel J.
  • 63
  • 1
  • 4
  • So, what's the actual problem? – Andrew Marshall Feb 12 '12 at 00:18
  • What is your "list" action supposed to be doing? It's not a standard Rails REST action. – Andrew Marshall Feb 12 '12 at 00:30
  • for debugging i just tried to render some text, but if i create a view. – Miguel J. Feb 12 '12 at 00:32
  • views/admin/users/list.html.erb, and put out something to the browser, it gives me the same error. for localhost/admin/users, index is fine, and if i add a show method its all fine. but i dont know why when i go to localhost/admin/users/"something" the controller assumes that it got to be a show method. – Miguel J. Feb 12 '12 at 00:33

2 Answers2

4

You seem to not have an understanding of how Rails's RESTful routing works by default. I recommend reading the Resource Routing section of the Rails Guides. By default, when using resources in your routes, the show action is what is used to display a particular model record. You can customize this behavior to an extent in that you can change the URL that for the show action, but not the method name in the model:

resources :users, :path_names => { :new => 'list' }

If you are going to use RESTful routing (which you should), you should remove the default route (match ':controller(/:action(/:id))(.:format)'). Also, you can run rake routes at any time from the terminal to see details about your current routing configuration.

Andrew Marshall
  • 95,083
  • 20
  • 220
  • 214
1

Your on the right track, however, there are a few more steps involved to complete your solution for a backend admin CRUD section. Check out the following example of how to create it yourself:

https://stackoverflow.com/a/15615003/2207480

Community
  • 1
  • 1
Stefan Muntwyler
  • 408
  • 1
  • 4
  • 9