0

コントローラーから応答オブジェクトを操作したいのですが、次のような応答を取得できることがわかっています。

class HomeController < ApplicationController
  after_filter :generate_html

  def index

  end 

  def generate_html
    raise response.body # this will show response body content
  end  
 end

では、どうすればコントローラーを初期化してその応答オブジェクトを取得できますか?Railsアプリケーションでstatic_page_generatorを書きたいからです。

4

1 に答える 1

0

静的ページをレンダリングするだけの場合、最も簡単な方法は、コントローラー アクションでページをレンダリングすることです。

 class HomeController < ApplicationController

   def index
     # renders index.html.haml or index.html.erb 
     # which is in the /views/static folder
     render 'static/index'
   end 

   def home
     # renders home.html.haml or home.html.erb 
     # which is in the /views/static folder
     render 'static/home'
   end

 end

さらに、Rails アプリのフォルダーに配置したページはすべて/public静的であり、http://www.yoursite.com/index.html経由でページにアクセスすることでパブリックに表示できることに注意してください。

于 2011-06-23T01:36:11.267 に答える