如果在树结构中有一些静态页面。第一级使用 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"
这是我的路线.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?