# How do I generate a page from a controller from inside a model

**URL:** <https://www.ruby-forum.com/t/how-do-i-generate-a-page-from-a-controller-from-inside-a-model/141353>\
**Category:** Rails\
**Created:** [June 24, 2008, 10:54pm UTC](https://www.ruby-forum.com/t/how-do-i-generate-a-page-from-a-controller-from-inside-a-model/141353 "2008-06-24T22:54:38Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![srveit](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c67d28/32.png) [@srveit](https://www.ruby-forum.com/u/srveit)\
**Post date:** [June 24, 2008, 10:54pm UTC](https://www.ruby-forum.com/t/how-do-i-generate-a-page-from-a-controller-from-inside-a-model/141353/1 "2008-06-24T22:54:38Z")

</div>

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?
