# Default Render Action or Help Cleaning Up My View Folder

**URL:** <https://www.ruby-forum.com/t/default-render-action-or-help-cleaning-up-my-view-folder/190730>\
**Category:** Rails\
**Created:** [June 25, 2010, 11:43pm UTC](https://www.ruby-forum.com/t/default-render-action-or-help-cleaning-up-my-view-folder/190730 "2010-06-25T23:43:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chris\_Peters](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/7ea924/32.png) [@Chris\_Peters](https://www.ruby-forum.com/u/Chris_Peters)\
**Post date:** [June 25, 2010, 11:43pm UTC](https://www.ruby-forum.com/t/default-render-action-or-help-cleaning-up-my-view-folder/190730/1 "2010-06-25T23:43:27Z")

</div>

I have 30 actions which all render basically the same thing, basically  
their name and a message either indicating success or failure:

 \<%= "#{action\_name} Update Result" %\> \<%= message %\> 

The trouble is, in order to do this I have a layout (partly shown  
above) and then 30 blank files in my view directory named after the  
actions they are associated with. I see no reason I have to create 30  
blank view files. However, if I don’t create the file then Rails will  
not render the view because it will error out on not being able to  
find an associated view file for this action.

I have considered adding a render line to the bottom of every action,  
something like render :file =\> “layouts/mylayout” but it seems that’s  
more or less a brute force resolution like making 30 files is a brute  
force solution.

Can I specify a default file to render for every action in a  
controller? Someone has to know a more elegant, railsy solution to  
this problem!

Thanks for your help,

Chris

---

<div class="post-metadata">

**Author:** ![Chris\_Peters](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/7ea924/32.png) [@Chris\_Peters](https://www.ruby-forum.com/u/Chris_Peters)\
**Post date:** [June 26, 2010, 12:49am UTC](https://www.ruby-forum.com/t/default-render-action-or-help-cleaning-up-my-view-folder/190730/2 "2010-06-26T00:49:01Z")

</div>

You could use “after\_filter :default\_render” and then

private  
def default\_render  
render =\> …  
end

But probably there is a better sollution here:  
[http://api.rubyonrails.org/classes/ActionController/Layout/ClassMethods.html](http://api.rubyonrails.org/classes/ActionController/Layout/ClassMethods.html)

–  
Fernando B.

---

<div class="post-metadata">

**Author:** ![Chris\_Peters](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/7ea924/32.png) [@Chris\_Peters](https://www.ruby-forum.com/u/Chris_Peters)\
**Post date:** [June 26, 2010, 1:15am UTC](https://www.ruby-forum.com/t/default-render-action-or-help-cleaning-up-my-view-folder/190730/3 "2010-06-26T01:15:22Z")

</div>

The after\_filter thing I tried before, and it causes a double-render  
condition. I would then need to go through all the functions and do  
render :none or something to that effect… Which just goes back to  
the render at the end of each function problem.

Chris

---

<div class="post-metadata">

**Author:** ![Chris\_Peters](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/7ea924/32.png) [@Chris\_Peters](https://www.ruby-forum.com/u/Chris_Peters)\
**Post date:** [June 27, 2010, 1:22am UTC](https://www.ruby-forum.com/t/default-render-action-or-help-cleaning-up-my-view-folder/190730/4 "2010-06-27T01:22:54Z")

</div>

Maybe you could try “before\_filter” 🙂

But nothing on  
[http://api.rubyonrails.org/classes/ActionController/Layout/ClassMethods.htmlsolved](http://api.rubyonrails.org/classes/ActionController/Layout/ClassMethods.htmlsolved)  
your problem? :S

–  
Fernando B.
