#117 Semi-Static Pages
Jul 07, 2008 | 14 minutes | Controllers
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.
- Download:
- source codeProject Files in Zip (104 KB)
- mp4Full Size H.264 Video (23.6 MB)
- m4vSmaller H.264 Video (15.7 MB)
- webmFull Size VP8 Video (42.8 MB)
- ogvFull Size Theora Video (34.8 MB)
Resources
- Episode 42: with_options
- Episode 110: Gem Dependencies
- Episode 63: Model Name in URL
- static_actions Plugin
- nifty-generators
- Simple static pages
- acts_as_textiled Plugin
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
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
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
bash
sudo gem install RedCloth --source=http://code.whytheluckystiff.net
sudo gem install RedCloth --source=http://code.whytheluckystiff.net
rhtml
<%= simple_format @page.content%>
or
<%= textilize @page.content %>
or
<%= RedCloth.new(@page.content).to_html %>
<%= simple_format @page.content%> or <%= textilize @page.content %> or <%= RedCloth.new(@page.content).to_html %>

