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!