# Validation across controllers

**URL:** <https://www.ruby-forum.com/t/validation-across-controllers/112802>\
**Category:** Rails\
**Created:** [August 23, 2007, 12:36pm UTC](https://www.ruby-forum.com/t/validation-across-controllers/112802 "2007-08-23T12:36:15Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![AurSSSSlien\_Malisar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/d78d45/32.png) [@AurSSSSlien\_Malisar](https://www.ruby-forum.com/u/AurSSSSlien_Malisar)\
**Post date:** [August 23, 2007, 12:36pm UTC](https://www.ruby-forum.com/t/validation-across-controllers/112802/1 "2007-08-23T12:36:15Z")

</div>

Hello, here is my issue with an exemple!

Typical example: post and comments in REST design

* * *

class PostsController \< ApplicationController  
…

def show  
…  
@comments = @post.comments.find(:all, :order…blabla)  
end

…  
end

* * *

and

* * *

class CommentsController \< ApplicationController  
…

def create  
@comment =  
Post.find(params[:post\_id]).comments.new(params[:comment])  
@comment.user = current\_user  
if @comment.save  
redirect\_to post\_path(@comment.post)  
else  
# ??  
end  
end

…

## end

I’ve got two controllers. The template for the posts’ show action  
displays comments for the current post on the bottom of the page with  
a “add new comment” form (so directed to /comments/create). In the  
case of no validation errors, no problem, I can redirect. But in the  
other case (#?? in the code), how to render the posts controller’s  
show action while it is not in the same controller? If I do a  
redirect, I will lose the @comment variable I need to user in the  
template for error\_messages\_for…

Thanks!

---

<div class="post-metadata">

**Author:** ![AurSSSSlien\_Malisar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/d78d45/32.png) [@AurSSSSlien\_Malisar](https://www.ruby-forum.com/u/AurSSSSlien_Malisar)\
**Post date:** [August 24, 2007, 2:44pm UTC](https://www.ruby-forum.com/t/validation-across-controllers/112802/2 "2007-08-24T14:44:50Z")

</div>

I’m now wondering if it’s a good design but in REST, that’s one  
controller by resource type, isn’t it?
