Static pages controller


/ Published in: Ruby
Save to your folder(s)



Copy this code and paste it in your HTML
  1. class PagesController < ApplicationController
  2.  
  3. layout 'default'
  4.  
  5. def index
  6. end
  7.  
  8. def show
  9. action_name = params[:path].join('/')
  10. if page_exist?(action_name)
  11. render :action => action_name
  12. else
  13. render :action => "pages/404", :layout => true, :status => 404
  14. end
  15. end
  16.  
  17. private
  18.  
  19. def page_exist?(page_name)
  20. file_path = File.join(RAILS_ROOT, "app", "views", "pages", "#{page_name}.html.erb")
  21. return true if File.exists?(file_path)
  22. end
  23. end

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.