# I need to do some code that should be in a controller inside a render partial. How?

**URL:** <https://www.ruby-forum.com/t/i-need-to-do-some-code-that-should-be-in-a-controller-inside-a-render-partial-how/190540>\
**Category:** Rails\
**Created:** [June 22, 2010, 12:15pm UTC](https://www.ruby-forum.com/t/i-need-to-do-some-code-that-should-be-in-a-controller-inside-a-render-partial-how/190540 "2010-06-22T12:15:27Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![adistarmid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f14d63/32.png) [@adistarmid](https://www.ruby-forum.com/u/adistarmid)\
**Post date:** [June 22, 2010, 12:15pm UTC](https://www.ruby-forum.com/t/i-need-to-do-some-code-that-should-be-in-a-controller-inside-a-render-partial-how/190540/1 "2010-06-22T12:15:27Z")

</div>

I have an app that will be making a customer list to go in a pdf. The  
pdf part wasn’t bad using wicked\_pdf. The problem is keeping the  
controller code where it belongs.

The app has a print method in the controller. It does a render partial  
to loop through each customer. Once there it needs to make lists of  
attendance for each of the last 3 years to be part of each customers  
page. This is different for each customer, so it needs to be re-run  
each time. This is the part I want to get out of the view. Any way to  
have another method in the controller to be run for each customer?

---

<div class="post-metadata">

**Author:** ![adistarmid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f14d63/32.png) [@adistarmid](https://www.ruby-forum.com/u/adistarmid)\
**Post date:** [June 22, 2010, 12:18pm UTC](https://www.ruby-forum.com/t/i-need-to-do-some-code-that-should-be-in-a-controller-inside-a-render-partial-how/190540/2 "2010-06-22T12:18:58Z")

</div>

On 22 June 2010 07:42, Bob S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> The app has a print method in the controller. It does a render partial  
> to loop through each customer. Once there it needs to make lists of  
> attendance for each of the last 3 years to be part of each customers  
> page. This is different for each customer, so it needs to be re-run  
> each time. This is the part I want to get out of the view.

Sounds like the Customer model might make a good place for the method  
to live. In the view you can call @customer.go\_get\_my\_data …

---

<div class="post-metadata">

**Author:** ![adistarmid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f14d63/32.png) [@adistarmid](https://www.ruby-forum.com/u/adistarmid)\
**Post date:** [June 23, 2010, 11:34pm UTC](https://www.ruby-forum.com/t/i-need-to-do-some-code-that-should-be-in-a-controller-inside-a-render-partial-how/190540/3 "2010-06-23T23:34:50Z")

</div>

On 23 June 2010 22:18, Bob S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Thanks. That should work fine… Is there anything special to do to  
> make the method seen in the view?

As long as it’s a public method, it will be accessible wherever you  
have any instance of the class.

---

<div class="post-metadata">

**Author:** ![adistarmid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f14d63/32.png) [@adistarmid](https://www.ruby-forum.com/u/adistarmid)\
**Post date:** [June 23, 2010, 11:19pm UTC](https://www.ruby-forum.com/t/i-need-to-do-some-code-that-should-be-in-a-controller-inside-a-render-partial-how/190540/4 "2010-06-23T23:19:37Z")

</div>

Thanks. That should work fine… Is there anything special to do to  
make the method seen in the view?

Bob

---

<div class="post-metadata">

**Author:** ![adistarmid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f14d63/32.png) [@adistarmid](https://www.ruby-forum.com/u/adistarmid)\
**Post date:** [June 23, 2010, 11:37pm UTC](https://www.ruby-forum.com/t/i-need-to-do-some-code-that-should-be-in-a-controller-inside-a-render-partial-how/190540/5 "2010-06-23T23:37:45Z")

</div>

as notes\*  
at ruby, u va access to all methods of class, wherever u have any  
instance of this class =)  
Â =)  
Best Regards, Dieinzige

On 23 Jun, 2010,at 09:33 PM, Michael P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

On 23 June 2010 22:18, Bob S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Thanks. That should work fine… Is there anything special to do to  
> make the method seen in the view?

As long as it’s a public method, it will be accessible wherever you  
have any instance of the class.

–  
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 removed\_email\_address@domain.invalid.  
To unsubscribe from this group, send email to  
removed\_email\_address@domain.invalid.  
For more options, visit this group at  
[http://groups.google.com/group/rubyonrails-talk?hl=en](http://groups.google.com/group/rubyonrails-talk?hl=en).
