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? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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?-- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
am i just going about this in the wrong way? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---