How to get rails response object in code?
I want to manipulate 开发者_Python百科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.
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
精彩评论