# Rendering a view from a model

**URL:** <https://www.ruby-forum.com/t/rendering-a-view-from-a-model/88175>\
**Category:** Rails\
**Created:** [March 8, 2007, 6:50pm UTC](https://www.ruby-forum.com/t/rendering-a-view-from-a-model/88175 "2007-03-08T18:50:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dougal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e495f1/32.png) [@dougal](https://www.ruby-forum.com/u/dougal)\
**Post date:** [March 8, 2007, 6:50pm UTC](https://www.ruby-forum.com/t/rendering-a-view-from-a-model/88175/1 "2007-03-08T18:50:54Z")

</div>

Hi peoples.

I have the following class method in a Rails model, in which I retrieve  
some objects from the DB…

@bubbles = Bubble.find(:all, :limit =\> 30) # What is the limit?  
open( “public/xml\_data/main\_data\_feed.xml”, “w” ) { | l | l.write  
ERB.new( IO.read( File.join( RAILS\_ROOT,  
“app/views/rssfeed/bubbles.rhtml” ) ) ).result }

When I attempt to run this with runner I get the following error…

./script/runner XmlInterface.generate  
/usr/local/lib/ruby/gems/1.8/gems/rails-1.2.2/lib/commands/runner.rb:47:  
(erb):14: You have a nil object when you didn’t expect it!  
(NoMethodError)  
You might have expected an instance of Array.  
The error occurred while evaluating nil.first

It seems as though the @bubble object is not being passed to the render,  
event though it _definitely_ has data in it.

Anyone any idea what is going wrong?

Thanks in advance.

Dougal [[http://douglasfshearer.com](http://douglasfshearer.com) ]

---

<div class="post-metadata">

**Author:** ![dougal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e495f1/32.png) [@dougal](https://www.ruby-forum.com/u/dougal)\
**Post date:** [March 9, 2007, 2:49am UTC](https://www.ruby-forum.com/t/rendering-a-view-from-a-model/88175/2 "2007-03-09T02:49:47Z")

</div>

You need to pass in the binding of the current method.

@bubbles = Bubble.find(:all, :limit =\> 30) # What is the limit?  
open( “public/xml\_data/main\_data\_feed.xml”, “w” ) { | l | l.write  
ERB.new( IO.read( File.join( RAILS\_ROOT,  
“app/views/rssfeed/bubbles.rhtml” ) ) ).result(binding) }

On Mar 9, 1:50 am, Douglas S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![dougal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e495f1/32.png) [@dougal](https://www.ruby-forum.com/u/dougal)\
**Post date:** [March 8, 2007, 8:50pm UTC](https://www.ruby-forum.com/t/rendering-a-view-from-a-model/88175/3 "2007-03-08T20:50:56Z")

</div>

Hi Douglas,

Douglas S. wrote:

> I have the following class method in a Rails model,  
> in which I retrieve some objects from the DB…

It’s often something simple like…

> @bubbles = Bubble.find  
> the @bubble object

OTOH, if that’s just a type (bubbles vs. bubble) then I’d say we need  
more  
info. In general, views get fed by a controller method rather than by  
methods in the model. Not sure what would happen if you didn’t have a  
controller method named bubbles. Have you tried putting the method  
that’s  
currently in your Bubble model in the controlleer?

Best regards,  
Bill
