How to Have One Resource in Routes for Namespace and Root Path Altogether - Rails 4

How to have one resource in routes for namespace and root path altogether - Rails 4

Oh wait ! There's also the possibility to use concerns !

concern :shared_actions do
resources :courses
resources :something_else
end

namespace :admin do
concerns :shared_actions
end
concerns :shared_actions # Will add it to the root namespace ^^

EDIT : apparently this is what this guy also tried to do :D

Rails routing: add (shallow) concern to root

Just write concerns: :namespaceable in the main file

Rails.application.routes.draw do

concern :namespaceable do
resources :comments do
resources :replies
...
end

concerns: :namespaceable # Will add to root namespace

end

Using same form and form_for in Rails with nested resources in namespace

Put the common features of the form inside the partial, and wrap it in the individual form_for:

<%= form_for [:admin, foo] do |f| %>
<%= render "foos/form", f: f %>
<% end %>

And:

<%= form_for [foo] do |f| %>
<%= render "foos/form", f: f %>
<% end %>


Related Topics



Leave a reply



Submit