# Where to put code - app controller, or app helper?

**URL:** <https://www.ruby-forum.com/t/where-to-put-code-app-controller-or-app-helper/54118>\
**Category:** Rails\
**Created:** [December 20, 2005, 12:56am UTC](https://www.ruby-forum.com/t/where-to-put-code-app-controller-or-app-helper/54118 "2005-12-20T00:56:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![bigdaddy71](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bbe5ce/32.png) [@bigdaddy71](https://www.ruby-forum.com/u/bigdaddy71)\
**Post date:** [December 20, 2005, 12:56am UTC](https://www.ruby-forum.com/t/where-to-put-code-app-controller-or-app-helper/54118/1 "2005-12-20T00:56:34Z")

</div>

I have a function i want to be used in both views and controllers:

```
def year_to_fiscal_year(year)
	# converts, say, an integer 2003 into '0304'
	year.to_s[2,2] << (year+1).to_s[2,2]
end

```

Where should i put it ?

---

<div class="post-metadata">

**Author:** ![bigdaddy71](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bbe5ce/32.png) [@bigdaddy71](https://www.ruby-forum.com/u/bigdaddy71)\
**Post date:** [December 20, 2005, 1:50am UTC](https://www.ruby-forum.com/t/where-to-put-code-app-controller-or-app-helper/54118/2 "2005-12-20T01:50:04Z")

</div>

Chris,

I just had a similar scenario.

Put that code in your app/controller/application.rb

Then, also in application.rb, add “helper\_method :year\_to\_fiscal\_year”

(That exposes it to your Views as well.)

Hope that helps,  
Regards,  
EJC

---

<div class="post-metadata">

**Author:** ![bigdaddy71](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bbe5ce/32.png) [@bigdaddy71](https://www.ruby-forum.com/u/bigdaddy71)\
**Post date:** [December 20, 2005, 2:06am UTC](https://www.ruby-forum.com/t/where-to-put-code-app-controller-or-app-helper/54118/3 "2005-12-20T02:06:53Z")

</div>

Chris

> I have a function i want to be used in both views and controllers:

If you try and place it in application\_helper.rb , controllers won’t  
have access to it =\> you’ll get an error message.  
=\> you must place it in ApplicationController.

Alain

---

<div class="post-metadata">

**Author:** ![bigdaddy71](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bbe5ce/32.png) [@bigdaddy71](https://www.ruby-forum.com/u/bigdaddy71)\
**Post date:** [December 20, 2005, 4:57am UTC](https://www.ruby-forum.com/t/where-to-put-code-app-controller-or-app-helper/54118/4 "2005-12-20T04:57:53Z")

</div>

Ed C. wrote:

> Chris,
> 
> I just had a similar scenario.
> 
> Put that code in your app/controller/application.rb
> 
> Then, also in application.rb, add “helper\_method :year\_to\_fiscal\_year”
> 
> (That exposes it to your Views as well.)
> 
> Hope that helps,  
> Regards,  
> EJC

Worked a treat, thanks!
