# Rendering original view

**URL:** <https://www.ruby-forum.com/t/rendering-original-view/159887>\
**Category:** Rails\
**Created:** [February 9, 2009, 8:10pm UTC](https://www.ruby-forum.com/t/rendering-original-view/159887 "2009-02-09T20:10:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![bingobob](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e480ec/32.png) [@bingobob](https://www.ruby-forum.com/u/bingobob)\
**Post date:** [February 9, 2009, 8:10pm UTC](https://www.ruby-forum.com/t/rendering-original-view/159887/1 "2009-02-09T20:10:43Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![bingobob](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e480ec/32.png) [@bingobob](https://www.ruby-forum.com/u/bingobob)\
**Post date:** [February 9, 2009, 10:06pm UTC](https://www.ruby-forum.com/t/rendering-original-view/159887/2 "2009-02-09T22:06:26Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![bingobob](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e480ec/32.png) [@bingobob](https://www.ruby-forum.com/u/bingobob)\
**Post date:** [February 10, 2009, 12:02pm UTC](https://www.ruby-forum.com/t/rendering-original-view/159887/3 "2009-02-10T12:02:14Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![bingobob](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e480ec/32.png) [@bingobob](https://www.ruby-forum.com/u/bingobob)\
**Post date:** [February 10, 2009, 7:58pm UTC](https://www.ruby-forum.com/t/rendering-original-view/159887/4 "2009-02-10T19:58:00Z")

</div>

am i just going about this in the wrong way?
