Adding controllers with a namespace administrator as a subfolder

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. so i created

rails creates an admin / Users controller

application | controllers | admin and 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:

 namespace :admin do resources :users end match ':controller(/:action(/:id))(.:format)' 

Im new to rails and i cant find a solution. I can not find it anywhere.

PROBLEM I'm trying to do acess:

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

and I get this error:

Unknown action The action 'show' was not found for Admin :: UsersController

+6
source share
2 answers

You don't seem to understand how Rails RESTful routing works by default. I recommend reading the Resource Routing section in Rails Guides . By default, when using resources in your routes, the show action is what is used to display a specific model entry. You can customize this behavior to the extent that you can change the URL for the show action, but not the method name in the model

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

If you intend to use RESTful routing (what you need), you should remove the default route ( match ':controller(/:action(/:id))(.:format)' ). In addition, you can run rake routes at any time from the terminal to view detailed information about your current routing configuration.

+4
source

On the right track, however, there are a few more steps to complete your solution for the CRUD section for the backend. See the following example of how to create it:

fooobar.com/questions/908239 / ...

+1
source

Source: https://habr.com/ru/post/908236/


All Articles