srveit
2008-Jun-24 20:53 UTC
How do I generate a page from a controller from inside a model
I have a model that I want to use for generating web pages. The pages
will be what is rendered by a controller action. The generated pages
will be FTP''ed to a hosting site where they will served up as static
pages.
One approach is to do it like ActionController::TestCase:
class Page
belongs_to :book
def contents
controller = BookController.new
request = TestRequest.new
response = TestResponse.new
request.path = "/books/#{book.id}" # show action
controller.process(request, response)
response.body
end
end
Then call page.contents will cause the BookController.show action to
be called which renders a page. The rendered page then would be
returned.
Is this the best way to do this?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---