Rails中运行静态网页
1、在模型中创建一个StaticPage类
?
class StaticPage Formats = { "html" => "text/html" }end
?
2、增加路由
?
map.page "page/:filename.:format", :controller => 'static_pages', :action => 'page'
?
3、控制器
?
class StaticPagesController < ApplicationController def page send_file "#{Rails.root}/app/views/static_pages/#{params[:filename]}.#{params[:format]}", :disposition => 'inline', :type => StaticPage::Formats[params[:format]] end end
?
4、把所有的静态网页都放在RAILS_ROOT/app/views/static_pages/文件夹下即可。