javacoder javacoder - 13 days ago 9
Ruby Question

The address directs me to the child?

I got two models; film model is the parent and the review model is the child. I expect the following code to direct me back to the film interface:

def create
@film = Film.find(params[:film_id])
@review = @film.reviews.new(review_params)
if @review.save
redirect_to film_path(@film)
else
render "films/#{@film.id}"
end
end


It renders me back to the following address: films/22/reviews when it suppose to direct me back to the same interface (films/22)?

I want to return back to the same interface so i can post the errors the user has made?

Answer

Try it in else part

flash[:alert] = @review.errors.full_messages.join(',  ') 
redirect_to :back