简体   繁体   中英

Namespaces and resources on Rails routes

I am developping an app with a backoffice ( admin ) which is restricted to some users, in order to modify content. And on the other side I have a webservice ( api ) which is accessed by clients.

So I've seperated the two parts in namespaces, and I realised that when I used scaffolding for a resource like questions for instance, the generated controller assumes the resource is admin::questions , but that's not what I wanted.

I expect to have:

/admin/questions to handle my questions (controller admin/questions_controller.rb)

/api/questions to serve my questions  (controller api/questions_controller.rb)

But in both cases, it's the same model.

Should I keep on using namespace or or use module in my routes? Does it go against the philosophy of rails resources?

Thanks for your input.

By running rails generate scaffold -h I saw an option called --skip-namespace . Is that what you're looking for?

From the documentation:

Usage:
  rails generate scaffold NAME [field[:type][:index] field[:type][:index]] [options]

Options:
    [--skip-namespace]                        # Skip namespace (affects only isolated applications)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM