`
CaiDeHen
  • 浏览: 89940 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

#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 %>
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics