# Clean way for a modular rails app?

**URL:** <https://www.ruby-forum.com/t/clean-way-for-a-modular-rails-app/122090>\
**Category:** Rails\
**Created:** [December 4, 2007, 3:46pm UTC](https://www.ruby-forum.com/t/clean-way-for-a-modular-rails-app/122090 "2007-12-04T15:46:37Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Karine\_D](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/e99b99/32.png) [@Karine\_D](https://www.ruby-forum.com/u/Karine_D)\
**Post date:** [December 4, 2007, 3:46pm UTC](https://www.ruby-forum.com/t/clean-way-for-a-modular-rails-app/122090/1 "2007-12-04T15:46:37Z")

</div>

Hello,

Right now, my Rails app has a controller with far too many functions.  
Some of these functions look like:

def generic\_function(params)  
case x  
when “module1”  
return module1\_function(params)  
when “module2”  
return module2\_function(params)  
[…]  
end  
end

I would like to move module1\_function (and all other module1 related  
stuff) in a separate file. Same thing for module2 (in another  
separate file) and so on. What is the proper, clean way to do that?

Thanks,  
Karine

---

<div class="post-metadata">

**Author:** ![Karine\_D](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/e99b99/32.png) [@Karine\_D](https://www.ruby-forum.com/u/Karine_D)\
**Post date:** [December 4, 2007, 4:58pm UTC](https://www.ruby-forum.com/t/clean-way-for-a-modular-rails-app/122090/2 "2007-12-04T16:58:52Z")

</div>

Try [http://agilewebdevelopment.com/plugins/embedded\_actions](http://agilewebdevelopment.com/plugins/embedded_actions)

Just like the traditional render :partial, embedded actions allow you  
to  
refactor your views and extract presentation logic and templates into  
separate  
files.

Unlike partials, embedded actions also let you define business logic  
to be  
performed before the partial is included. That logic is encapsulated  
in the  
already well understood metaphor of an action inside a controller.

So a simple call like

\<%= embed\_action :controller =\> “songs”, :action =\> “top10” %\>
