Answer the question
In order to leave comments, you need to log in
How to organize namespaces in Rails?
Hey! How to organize work with namespaces in rails? The simplest example is I have a guest page. When a guest goes to the user group, then from / it moves to /dashboard
There I have some controllers. For example, post controller. I also have a Post model (which, due to the presence of the admin in the /admin namespace, should not be moved to Dashboard::Post).
As a result, we get the following routing:
root 'guest#index'
namespace :dashboard do
resources :posts
end
namespace :admin do
resources :users, :posts
end
form_for @post
should refer to /dashboard/posts/new, and if we are in the /admin namespace, then to /admin/posts/new Answer the question
In order to leave comments, you need to log in
look at what I FOUND by writing in Google: "namespace rails"
rusrails.ru/rails-routing#prostranstvo-imen-kontro... it's
amazing what possibilities the keyboard gives
So if you have different namespaces, then the views will be taken from different folders: for the dashboard - from views/dashboard, and for the admin - from views/admin. So there shouldn't be any problems.
And if you mix views, and load the same views in different namespaces, then you should think about whether you need to do this. At some point, one of the namespaces will need to make its own representations.
One option I've seen is to create the Dashboard::Post and Admin::Post classes to inherit from Post. I didn’t use this myself, perhaps this solution has some weaknesses, since it is not very common.
I solved a similar problem by explicitly specifying the namespaceform_for [:admin, @post]
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question