- 论坛徽章:
- 0
|
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[params[:format]]
- end
-
- end
复制代码 4、把所有的静态网页都放在RAILS_ROOT/app/views/static_pages/文件夹下即可。 |
|