中关村村草 发表于 2011-08-25 16:57

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/文件夹下即可。

coolesting 发表于 2011-08-25 21:28

效率如何, 和服务器直接读取静态文件比 ?

2gua 发表于 2011-08-26 12:38

有一层转换后,肯定跟服务器直接读取在效率上要差一点。
页: [1]
查看完整版本: Rails中运行静态网页