ツリー構造にいくつかの静的ページがある場合。最初のレベルのものは static_pages_controller.rb を使用して提供され、routes.rb には次のものがあります。
get '/static_pages/news' , :to => 'static_pages#news' , :as => 'news'
get '/static_pages/index' , :to => 'static_pages#index' , :as => 'index'
....
上記が存在します
app\views\static_pages\news.html.erb
app\views\static_pages\index.html.erb
....
ここで、static_pages ルートの下に他の静的ページをいくつか貼り付けました。
app\views\static_pages\ermis\news.html.erb
app\views\static_pages\ermis\index.html.erb
....
これをroutes.rbに追加しました:
get '/static_pages/ermis/news' , :to => 'static_pages#news' , :as => 'news'
get '/static_pages/ermis/index' , :to => 'static_pages#index' , :as => 'index'
アクションが既に存在するため(親フォルダー)、上記は機能しません。だから私はファイルの名前を変更するという面倒なステップを踏んだ(もっと良い方法があるに違いない?!?)
app\views\static_pages\ermis\ermisnews.html.erb
app\views\static_pages\ermis\ermisindex.html.erb
....
そして私のroutes.rbはなりました
get '/static_pages/ermis/news' , :to => 'static_pages#ermisnews' , :as => 'ermisnews'
get '/static_pages/ermis/index', :to => 'static_pages#ermisindex', :as => 'ermisindex'
....
コントローラーは空です
class StaticPagesController < ApplicationController
end
ページが提供されないのはなぜですか? 私は何が欠けていますか?
クリックすると
<%= link_to("Ermis", ermisnews_path, class: 'pictureTitle') %>
私は得る
"The action 'ermisnews' could not be found for StaticPagesController"
ここに私のroutes.rb
Prefix Verb URI Pattern Controller#Action
root GET / static_pages#index
ermisindex GET /static_pages/ermis/index(.:format) static_pages#ermisindex
ermisnews GET /static_pages/ermis/news(.:format) static_pages#ermisnews
news GET /static_pages/news(.:format) static_pages#news
index GET /static_pages/index(.:format) static_pages#index
注: static_pages の .erb ファイルを直接指すリンクを使用してもエラーは発生しません
<%= link_to("News" , news_path , class: 'pictureTitle')
Question:
1) How can I use the same controller to also serve static pages underneath /static_pages eg. /static_pages/ermis
2) Am I obliged to actually rename the files to have them represent unique actions?