I have the following model classes:
class Upload < ActiveRecord::Base
...
has_many :reviews, :order => "created_at DESC"
...
end
class Review < ActiveRecord::Base
...
belongs_to :upload
belongs_to :user
validates_presence_of :description
...
end
My upload/show view has a form for to capture a review for the specific upload:
<% form_for(@review) do |f| %>
<%= f.error_messages %>
...
<p>
<%= f.text_area :description, :rows => 5, :cols => 80 %>
</p>
...
<p>
<%= f.submit 'Submit Review' %>
</p>
<% end %>
When the review validation fails how do I display the error messages in the review form that is part of the upload/show view?
My ReviewController does this:
def create @review = current_user.reviews.new(params[:review])
if @review.save
flash[:notice] = 'Review was successfully created.'
redirect_to( @review.upload )
else
render :action => :new
end
end
Obviously render :action => :new
does not work because I need to display the show action of the UploadsController and not the new action of the ReviewsController.
I'm pretty sure there is a simple way to do this, I just can't figure it out!