Skip to content

Instantly share code, notes, and snippets.

@namutaka
Created May 27, 2012 10:18
Show Gist options
  • Save namutaka/2803188 to your computer and use it in GitHub Desktop.
Save namutaka/2803188 to your computer and use it in GitHub Desktop.
レイアウト付きで静的ページを表示させるコントローラ
#
# レイアウト付きで静的ページを表示させるコントローラ
#
# routes.rb
# map.connect "/hoge/*paths", :controller => 'static_page', :action => 'index', :subdir => 'hoge'
#
class StaticPageController < ApplicationController
#viewファイルの配置場所を別途用意する
STATIC_VIEWS_BASE = "app/static_views"
append_view_path STATIC_VIEWS_BASE
def index
view_file_path = File.join(Rails.root, STATIC_VIEWS_BASE,
params[:subdir], params[:paths].presence || 'index')
render :file => view_file_path, :layout => true
rescue ActionView::MissingTemplate
raise MissingFile, "Cannot read file #{view_file_path}"
end
end
#ファイルパスを追加
#・rake stats用
#・rake doc:app用
#・rake test
#テストフォルダの構成。
#fixtureの構成。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment