Rails中运行静态网页
Rails中运行静态网页.1、在模型中创建一个StaticPage类
Ruby代码class StaticPage
Formats = {
"html" => "text/html"
}
end 2、增加路由
Ruby代码map.page "page/:filename.:format", :controller => 'static_pages', :action => 'page'
3、控制器
Ruby代码class StaticPagesController < ApplicationController
def page
send_file "#{Rails.root}/app/views/static_pages/#{params[:filename]}.#{params[:format]}",
:disposition => 'inline', :type => StaticPage::Formats]
end
end 4、把所有的静态网页都放在RAILS_ROOT/app/views/static_pages/文件夹下即可。 效率如何, 和服务器直接读取静态文件比 ? 有一层转换后,肯定跟服务器直接读取在效率上要差一点。
页:
[1]