Please advise on render:partial form.

Background:

On my application users can post Castings [class Casting] now i want other users to be abel to post Comments on the Castings [Castingcomment].

Approach:

views/castings/show.html.erb '

   <%= render :partial => 'castingcomment_form' %>

app/controllers/castingcomments_controller.rb

   def create     @castingcomment = Castingcomment.new( params[:castingcomment] )     if @castingcomment.save       redirect_to :controller => "castings", :action => "show", :id => @castingcomment.casting_id     else       # what to write here ?     end   end

The problem:

When the form validates it all works, but if create goes to a error what to write there ? I need to render the same page (views/casting/ show.html.erb) again to show the error to the user.

Please advice me, i have been looking at this for hours.

/Niklas.

The problem:

When the form validates it all works, but if create goes to a error what to write there ? I need to render the same page (views/casting/ show.html.erb) again to show the error to the user.

Call the render method (there are loads of ways you can call it. I'd expect this approach to be covered by almost any "write a something app in 5 minutes" type tutorial

Fred

In the create action, that typically ends up being render :action => :new

Garrett Lancaster

compose-unknown-contact.jpg

Looks like you have Casting has_many :comments, and you have a comment form on your Casting show page. If so, then you just need to render your casting show page. But this requires you to supply the Casting show page the @casting variable in your controller.

... else   @casting = Casting.find(@castingcomment.casting_id)   render 'casting/show.html.erb' end

I would recommend that you not have a Castingcomment class. Say you need comments for different models, then you could have Anothermodelcomment class, etc. Consider having just a Comment model and create polymorphic associations from that model.

Here's a refernce http://www.arailsdemo.com/posts/20

Here is some background for that post http://www.arailsdemo.com/posts/16

Thanks, will have a look @ polymorphic associations, looks like what i want! If i can get it to work. Thanks again!

/Niklas.