#117 Semi-Static Pages

Static pages can sometimes be a little awkward to add to a Rails app. See a couple different solutions to this problem in this episode.
# pages_controller.rb
def show
if params[:permalink]
@page = Page.find_by_permalink(params[:permalink])
raise ActiveRecord::RecordNotFound, "Page not found" if @page.nil?
else
@page = Page.find(params[:id])
end
end

# routes.rb

map.static 'static/:permalink', :controller => 'pages', :action => 'show'

# or

map.with_options :controller => 'info' do |info|
info.about 'about', :action => 'about'
info.contact 'contact', :action => 'contact'
info.privacy 'privacy', :action => 'privacy'
end

<%= simple_format @page.content%>
or
<%= textilize @page.content %>
or
<%= RedCloth.new(@page.content).to_html %>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章