0

I want to manipulate response object from a controller, I just know I can get response like this:

class HomeController < ApplicationController
  after_filter :generate_html

  def index

  end 

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

Now how can I initialize a controller and get its response object? Because I want to write static_page_generator in a rails application.

iwasrobbed
  • 46,496
  • 21
  • 150
  • 195
qichunren
  • 4,405
  • 7
  • 37
  • 48

1 Answers1

0

If you just want to render static pages, the easiest way to do that is just render the page in your controller action.

 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

Additionally, remember that any page you put into the /public folder in the Rails app is static and publicly viewable by accessing the page via http://www.yoursite.com/index.html

iwasrobbed
  • 46,496
  • 21
  • 150
  • 195
  • Thanks for your reply.But I want to execute code to get response, not open a browser to see it. – qichunren Jul 01 '11 at 07:27
  • Do you mean to generate an HTTP response or to generate JSON/XML? What are you doing with the "response" that you are trying to generate? – iwasrobbed Jul 05 '11 at 14:09