# How does form validation works on restful controllers

**URL:** <https://www.ruby-forum.com/t/how-does-form-validation-works-on-restful-controllers/117600>\
**Category:** Rails\
**Created:** [October 18, 2007, 1:32pm UTC](https://www.ruby-forum.com/t/how-does-form-validation-works-on-restful-controllers/117600 "2007-10-18T13:32:46Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tarscher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/8491ac/32.png) [@Tarscher](https://www.ruby-forum.com/u/Tarscher)\
**Post date:** [October 18, 2007, 1:32pm UTC](https://www.ruby-forum.com/t/how-does-form-validation-works-on-restful-controllers/117600/1 "2007-10-18T13:32:46Z")

</div>

Hi all,

Let’s assume I have a calendar show view (calendar controller). On  
that view you can view a calendar with all its events. You can also  
add, edit and delete events (via the events controller) on that same  
view.

Let’s assume the user creates a new event but forgets to fill in some  
data and the validation (and insert operation) fails. You want to use  
the render :action =\> ‘calendars/show’ method to show the validation  
error on the form in the calendar controller.

The problem I’m facing is that when you render the calendar view you  
need other variables (like all the events of the calendar). Of course  
you can add @events = Event.find(:all) in the create method of the  
events controller but in my opinion this completely ruins the restful  
philosophy: your create method isn’t a real create method anymore, it  
has also become an index method.

I’m really interested in your opinion and how you design your  
controllers to solve this problem.

Many thanks in advance.  
Stijn

---

<div class="post-metadata">

**Author:** ![Tarscher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/8491ac/32.png) [@Tarscher](https://www.ruby-forum.com/u/Tarscher)\
**Post date:** [October 18, 2007, 7:19pm UTC](https://www.ruby-forum.com/t/how-does-form-validation-works-on-restful-controllers/117600/2 "2007-10-18T19:19:31Z")

</div>

This is one of those fundamental design issues that some people might  
argue I get wrong.

I would put the event handling, editing, and all that in the calendar  
controller.

Why? Because events don’t really live outside that context. They are  
modified through the calendar the user sees, and they are displayed on  
it. Sure, there are event lists that you might have outside it, but  
isn’t a list of events just a schedule, which is another form of  
calendar?

In my code, I have “users”, “toons”, and “avatars” – the Avatar is a  
small picture that is specific to a Toon. I put all the avatar logic  
in toon\_controller.rb, since modifying a toon is done along the same  
lines as modifying the Toon attributes of level, class, etc. From a  
user’s point of view, and from mine, an Avatar is just another  
attribute on a Toon.

When I think of a calendar, I think of events on it. I don’t think of  
an event standing alone, I think of it as something that occurs on a  
specific day and time, which is a calendar.

–Michael
