Here''s my form <h1 id="school_name"><%=h @school.name %> (<%=h @school.place %>)</h1> <h1 id="school_url"><%= link_to @school_url, @school.url %></h1> <% form_for [@school, Review.new] do |f| %> <p> <%= f.label :first_name, "First Name" %><br /> <%= f.text_field :first_name, :length => 40 %> </p> <p> <%= f.label :body, "Leave a review..." %><br /> <%= f.text_area :body, :cols => 40, :rows => 6 %> </p> <p><%= f.submit "Add Review" %></p> <% end %> <% unless @school.reviews == [] %> <div id="reviews"> <%= render :partial => @school.reviews %> </div> <% end %> --- my routes map.resources :schools, :has_many => :reviews and my controller for reivews class ReviewsController < ApplicationController def create @school = School.find(params[:school_id]) @review = @school.reviews.build(params[:review]) @review.save redirect_to @school end end ----- I''d like to show validation errors in the initial form, so how do I do the line... <% form_for [@school, Review.new] do |f| %> Is that right? I realise i need to update the controller to render new if the record doesnt save... -- 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 -~----------~----~----~----~------~----~------~--~---
bingo bob
2009-Feb-16 15:31 UTC
Re: displaying validation messages - what do i do in my form
so here''s my reviews controller, i''d like to return to the schools show action and show errors if the record not saved. class ReviewsController < ApplicationController def create @school = School.find(params[:school_id]) @review = @school.reviews.build(params[:review]) if @review.save redirect_to @school else render :action => "new" end end end -- 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 -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2009-Feb-16 15:35 UTC
Re: displaying validation messages - what do i do in my form
On 16 Feb 2009, at 15:27, bingo bob wrote:> > > I''d like to show validation errors in the initial form, so how do I do > the line... > > <% form_for [@school, Review.new] do |f| %> >You don''t want Review.new. You want to use the instance of review that had the errors on it. This will also means that the text boxes etc. will be filled with what the user typed in before. You can use f.error_messages_for to display the errors or you can roll your own thing if you don''t like the output that generates but the key thing is that you need to use th instance which has errors on it. Fred> Is that right? > > > I realise i need to update the controller to render new if the record > doesnt save... > -- > 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 -~----------~----~----~----~------~----~------~--~---
bingo bob
2009-Feb-16 17:09 UTC
Re: displaying validation messages - what do i do in my form
OK, kind of got you...appreciate i need the instance with the errors in it, how do i achieve that? so not this...>> <% form_for [@school, Review.new] do |f| %>But this doesn''t work for me..>> <% form_for [@school, @review.new] do |f| %>-- 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 -~----------~----~----~----~------~----~------~--~---
Ar Chron
2009-Feb-16 17:35 UTC
Re: displaying validation messages - what do i do in my form
> But this doesn''t work for me.. > >>> <% form_for [@school, @review.new] do |f| %>Your form_for should be using @school, @review. In the controller new method, just like you do a (I hope) @school = School.new do a @review = Review.new -- 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 -~----------~----~----~----~------~----~------~--~---
bingo bob
2009-Feb-16 18:42 UTC
Re: displaying validation messages - what do i do in my form
there is no new method... just create... here''s my reviews controller class ReviewsController < ApplicationController def create @school = School.find(params[:school_id]) @review = @school.reviews.build(params[:review]) if @review.save redirect_to @school else render :action => "new" end end end and here''s my school show view... <h1 id="school_name"><%=h @school.name %> (<%=h @school.place %>)</h1> <h1 id="school_url"><%= link_to @school_url, @school.url %></h1> <% form_for [@school, Review.new] do |f| %> <p> <%= f.label :first_name, "First Name" %><br /> <%= f.text_field :first_name, :length => 40 %> </p> <p> <%= f.label :body, "Leave a review..." %><br /> <%= f.text_area :body, :cols => 40, :rows => 6 %> </p> <p><%= f.submit "Add Review" %></p> <% end %> <% unless @school.reviews == [] %> <div id="reviews"> <%= render :partial => @school.reviews %> </div> <% end %> -- 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 -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2009-Feb-16 19:08 UTC
Re: displaying validation messages - what do i do in my form
On 16 Feb 2009, at 17:09, bingo bob wrote:> > OK, kind of got you...appreciate i need the instance with the errors > in > it, how do i achieve that? > > so not this... > >>> <% form_for [@school, Review.new] do |f| %> > > But this doesn''t work for me.. > >>> <% form_for [@school, @review.new] do |f| %>if @review is the object with your errors you don''t need to call new - just @review will do Fred>>> > > > -- > 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 -~----------~----~----~----~------~----~------~--~---
bingo bob
2009-Feb-16 19:30 UTC
Re: displaying validation messages - what do i do in my form
ok thanks fred... but... class ReviewsController < ApplicationController def create @school = School.find(params[:school_id]) @review = @school.reviews.build(params[:review]) if @review.save redirect_to @school else # what goes here ??? end end end -- 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 -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2009-Feb-16 19:33 UTC
Re: displaying validation messages - what do i do in my form
On 16 Feb 2009, at 19:30, bingo bob wrote:> > ok thanks fred... but... > > class ReviewsController < ApplicationController > > def create > > @school = School.find(params[:school_id]) > > @review = @school.reviews.build(params[:review]) > > if @review.save > redirect_to @school > else > # what goes here ??? > end >exactly what you had before - just render your ''new'' action Fred --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
bingo bob
2009-Feb-16 19:57 UTC
Re: displaying validation messages - what do i do in my form
i don''t have a new action or view in my reviews controller... my comments are being entered and displayed on the schools show page. -- 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 -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2009-Feb-16 20:16 UTC
Re: displaying validation messages - what do i do in my form
On Feb 16, 7:57 pm, bingo bob <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> i don''t have a new action or view in my reviews controller... > > my comments are being entered and displayed on the schools show page.then pass whatever you need to pass to render to get it to render the form again. You know where that file is, I don''t Fred> -- > Posted viahttp://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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
bingo bob
2009-Feb-17 07:26 UTC
Re: displaying validation messages - what do i do in my form
Arrrr! I see...sorry being dopey, just enhance the render command - I read you can do this elesewhere... BUT, It still deosnt work! class ReviewsController < ApplicationController def create @school = School.find(params[:school_id]) @review = @school.reviews.build(params[:review]) if @review.save redirect_to @school else render :action => "show", :controller => "schools" # here....!!!! end end end ===== it''s trying to go here... Showing app/views/reviews/show.html.erb where line #42 raised: undefined method `edit_review_path'' for #<ActionView::Base:0x21c2260> It should go back to here I suppose... http://localhost:3000/schools/2 -- 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 -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2009-Feb-17 11:22 UTC
Re: displaying validation messages - what do i do in my form
On 17 Feb 2009, at 07:26, bingo bob wrote:> > > Arrrr! I see...sorry being dopey, just enhance the render command - I > read you can do this elesewhere... >which bit of the view is causing this ? Fred> > BUT, It still deosnt work! > > class ReviewsController < ApplicationController > > def create > > @school = School.find(params[:school_id]) > > @review = @school.reviews.build(params[:review]) > > if @review.save > redirect_to @school > else > render :action => "show", :controller => "schools" # > here....!!!! > end > > > end > > end > > > > > > ===== it''s trying to go here... > > Showing app/views/reviews/show.html.erb where line #42 raised: > undefined method `edit_review_path'' for #<ActionView::Base:0x21c2260> > > It should go back to here I suppose... > > http://localhost:3000/schools/2 > > -- > 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 -~----------~----~----~----~------~----~------~--~---
bingo bob
2009-Feb-17 13:50 UTC
Re: displaying validation messages - what do i do in my form
ignore the previous error... basically its not looking as my schools controller even though i specficy it. here''s the view.. <h1 id="school_name"><%=h @school.name %> (<%=h @school.place %>)</h1> <h1 id="school_url"><%= link_to @school_url, @school.url %></h1> <% form_for [@school, @review] do |f| %> <p> <%= f.label :first_name, "First Name" %><br /> <%= f.text_field :first_name, :length => 40 %> </p> <p> <%= f.label :body, "Leave a review..." %><br /> <%= f.text_area :body, :cols => 40, :rows => 6 %> </p> <p><%= f.submit "Add Review" %></p> <% end %> <% unless @school.reviews == [] %> <div id="reviews"> <%= render :partial => @school.reviews %> </div> <% end %> ad here''s the cont. class ReviewsController < ApplicationController def create @school = School.find(params[:school_id]) @review = @school.reviews.build(params[:review]) if @review.save redirect_to @school else render :controller => "schools", :action => "show" end end end --------- result is this when validation fails... Template is missing Missing template reviews/show.erb in view path /Users/rupe/Sites/schools/app/views: which is weird because I said... render :controller => "schools", :action => "show" -- 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 -~----------~----~----~----~------~----~------~--~---