ショーアクションのルートを整理する方法について混乱しています。現時点では、特定のガイドラインを選択して「表示」すると、URLには次のように表示されます。
/ガイドライン/1
ここで、1はガイドラインIDです。
言いたいのですが
/タイトル
(これは、表示されているガイドラインのタイトルです)。ルートでこれを管理する方法がわかりません。現時点で私のルートは
get 'guideline/:id', to: 'guidelines#show', as: :seeguideline
しかし、これは私が述べたようにガイドライン/ 1を示しているだけなので、私は何か間違ったことをしていることに気づきます
私の見解はこれにリンクしています
<%= link_to guideline.title, seeguideline_path(id: guideline.id) %>
guides_controller.rbでアクションを表示します
def show
@guideline = Guideline.where(title: params[:title]).first
respond_to do |format|
format.html # show.html.erb
format.json { render json: @guideline }
end
end
ルートは
ActiveAdmin.routes(self)
devise_for :admin_user, ActiveAdmin::Devise.config
get "guidelines/topic"
get "guidelines/topichospital"
get "guidelines/topicspecialty"
get "guidelines/favourite"
devise_for :users
devise_scope :user do
get 'signup', to: 'devise/registrations#new', as: :register
get 'login', to: 'devise/sessions#new', as: :login
get 'logout', to: 'devise/sessions#destroy', as: :logout
get 'edit', to: 'devise/registrations#edit', as: :edit
put 'users' => 'devise/registrations#update', :as => 'user_registration'
get 'about', to: 'about#about', as: :about
end
resources :guidelines
get 'guidelines', to: 'guidelines#index', as: :guidelines
get 'favourites', to: "favourites#show", as: :favourites
get 'topics', to: 'guidelines#list', as: :topics
get 'hospitals', to: 'guidelines#listhospital', as: :hospitals
get 'specialties', to: 'guidelines#listspecialty', as: :specialties
root :to => 'guidelines#index'
get '/:id', to: 'profiles#show', as: :myprofile
get '/:title', to: 'guidelines#show', as: :seeguideline