Rendering original view

def create

# next statement is original and is removed
# @review = Review.new(params[:review])

@school = School.find(params[:school_id])
# @review = @school.reviews.create!(params[:review])
@review = @school.reviews.build(params[:review])


respond_to do |format|
  if @review.save

    flash[:notice] = 'Review was successfully created.'
    # format.html { redirect_to(@review) }
    format.html { redirect_to(@school) }
    format.xml  { render :xml => @review, :status => :created,

:location => @review }
else
# format.html { render :action => “new” }
format.html { render :action => “new” } # <----- HERE
format.xml { render :xml => @review.errors, :status =>
:unprocessable_entity }
end
end
end

In this view the line

    format.html { render :action => "new" }

renders the reviews new method when the validation fails…thing is I
want to show the school and the error messages, (schools controller show
method) like this line, format.html { redirect_to(@school) }.

any help on how to do this?

Why do you really want to render the show method of schools_controller?
Do you not render the new-action of the schools_controller? the bad form
was send from the new action of the schools controller isn’t it?

format.html { render :action => “new”, :controller => ‘schools’ }

bingo bob wrote:

def create

# next statement is original and is removed
# @review = Review.new(params[:review])

@school = School.find(params[:school_id])
# @review = @school.reviews.create!(params[:review])
@review = @school.reviews.build(params[:review])


respond_to do |format|
  if @review.save

    flash[:notice] = 'Review was successfully created.'
    # format.html { redirect_to(@review) }
    format.html { redirect_to(@school) }
    format.xml  { render :xml => @review, :status => :created,

:location => @review }
else
# format.html { render :action => “new” }
format.html { render :action => “new” } # <----- HERE
format.xml { render :xml => @review.errors, :status =>
:unprocessable_entity }
end
end
end

In this view the line

    format.html { render :action => "new" }

renders the reviews new method when the validation fails…thing is I
want to show the school and the error messages, (schools controller show
method) like this line, format.html { redirect_to(@school) }.

any help on how to do this?

K. R. wrote:

Why do you really want to render the show method of schools_controller?
Do you not render the new-action of the schools_controller? the bad form
was send from the new action of the schools controller isn’t it?

format.html { render :action => “new”, :controller => ‘schools’ }

I’m pretty confused now as to how to do this. I’m hopig from one
controller to another and maybe that’s my problem (I shouldn’t do this
perhaps).

The show in Schools is what I’d like, reason is this…

I setup the up with Schools and Reviews controllers

I edit the Schools show action so that it display a form allowing
reviews to be submitted (submits to the reviews via the line above

@review = @school.reviews.build(params[:review])

works fine.

Under the form on the Schools show page I display all the reviews for
that school… @School.reviews

works fine.

Thing is, when I introduce validation to the review model (presence of
first_name for example), it doesnt work - I’d like it when the
validation failed to return to the schools controller show method and
display the error?

Any insight appreciated.

am i just going about this in the wrong way?