# Render views from outside of controller for example in my modules in Lib directory

**URL:** <https://www.ruby-forum.com/t/render-views-from-outside-of-controller-for-example-in-my-modules-in-lib-directory/173373>\
**Category:** Rails\
**Created:** [August 7, 2009, 3:25pm UTC](https://www.ruby-forum.com/t/render-views-from-outside-of-controller-for-example-in-my-modules-in-lib-directory/173373 "2009-08-07T15:25:40Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![firelinemx](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/8edcca/32.png) [@firelinemx](https://www.ruby-forum.com/u/firelinemx)\
**Post date:** [August 7, 2009, 3:25pm UTC](https://www.ruby-forum.com/t/render-views-from-outside-of-controller-for-example-in-my-modules-in-lib-directory/173373/1 "2009-08-07T15:25:40Z")

</div>

i render view from outside of controllers in my a module in lib  
folder, here is my render method:

```
  def render(options, assigns = {})
    view = ActionView::Base.new

```

(ActionController::Base.view\_paths,assigns)  
view.render options  
end

and i call it like this:  
render(:file=\>"#{template\_path}.html.erb",:locals =\> locals)

every things fine in rendered page, i can use locals but when i use  
FORM\_FOR in rendered view, i get this error message:

You have a nil object when you didn’t expect it!  
The error occurred while evaluating nil.url\_for

please help me!

---

<div class="post-metadata">

**Author:** ![firelinemx](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/8edcca/32.png) [@firelinemx](https://www.ruby-forum.com/u/firelinemx)\
**Post date:** [August 7, 2009, 5:15pm UTC](https://www.ruby-forum.com/t/render-views-from-outside-of-controller-for-example-in-my-modules-in-lib-directory/173373/2 "2009-08-07T17:15:43Z")

</div>

firelinemx wrote:

> i render view from outside of controllers in my a module in lib  
> folder, here is my render method:
> 
> ```
> def render(options, assigns = {})
> view = ActionView::Base.new
> 
> ```
> 
> (ActionController::Base.view\_paths,assigns)  
> view.render options  
> end
> 
> and i call it like this:  
> render(:file=\>"#{template\_path}.html.erb",:locals =\> locals)
> 
> every things fine in rendered page, i can use locals but when i use  
> FORM\_FOR in rendered view, i get this error message:
> 
> You have a nil object when you didn’t expect it!  
> The error occurred while evaluating nil.url\_for
> 
> please help me!

Not a fan of any rendering showing up in your models but in your  
controller code, did you assign the model of interest to your locals?  
i.e. does the locals() in :locals =\> locals bring up your model of  
interest… as that is what you are passing to the view.
