In my view directory I have two subdirectory master/hotels and cruds. In cruds I have several files(new, index, edit, show). master only has index file. Now I set "index" in cruds as root and I can link directory to "new" by add this path in a button like this:
= link_to "new", url_for(new_master_hotels_path), class: "btn btn-white btn-sm"
The problem is, I cannot link to other path like edit_master_hotels_path ore show_show_hotels_path and I don't know why "new" can and others cannot. I use wice_grid plugin in my project. my routes here
# -*- coding: utf-8 -*-
SptHunter::Application.routes.draw do
post "versions/:id/revert" => "versions#revert", :as => "revert_version"
devise_for :admin_users
resources :flights
mount RailsAdmin::Engine => '/rails_admin', :as => 'rails_admin'
resources :dashboard, only: [:index]
root to: 'master/hotels#index'
resources :reservations do
collection do
get 'callcenter'
end
end
concern :importable do
collection do
post :import
end
end
#resources :products do
# collection { post :import }
#end
# マスタ
namespace :master do
# マスタ(商品)
resources :hotels, concerns: [:importable]
resources :flights, concerns: [:importable]
resources :options, concerns: [:importable]
resources :events, concerns: [:importable]
resources :products, concerns: [:importable]
resources :hotel_room_stocks, concerns: [:importable]
# マスタ(取引先)
resources :agencies, concerns: [:importable]
resources :companies, concerns: [:importable]
resources :clients, concerns: [:importable]
# マスタ(設定)
resources :product_categories, concerns: [:importable]
resources :delivery_categories, concerns: [:importable]
resources :airports, concerns: [:importable]
resources :areas, concerns: [:importable]
resources :prefectures, concerns: [:importable]
resources :hotel_rooms, concerns: [:importable]
# マスタ(社内)
resources :admin_users, concerns: [:importable]
resources :admin_news, concerns: [:importable]
end
end
and my view structure is: -master/hotels(index) -cruds(new,form,show,edit,index) hope it help.
If you have subdirectory
a & b, your routes should accommodate them like this:
#config/routes.rb
namespace 'subdirectory' do
#routes here
resources :demo
end
This basically means you have to maintain the resource-based Rails routing infrastructure within the subdomain, meaning your routes will basically be the same as if you didn't have a subdirectory set up.
Update
Surely you could fix your routes to be DRY like this:
namespace :master do
# マスタ(商品)
resources :hotels, :flights, :options, :events, :products, :hotel_room_stocks, concerns: [:importable]
# マスタ(取引先)
resources :agencies, :companies, :clients, concerns: [:importable]
# マスタ(設定)
resources :product_categories, :delivery_categories, :airports_categories, :areas, :prefectures, :hotel_rooms, concerns: [:importable]
# マスタ(社内)
resources :admin_users, :admin_news concerns: [:importable]
end