Background: On my application users can post Castings [class Casting] now i want other users to be abel to post Comments on the Castings [Castingcomment]. Approach: views/castings/show.html.erb '' <%= render :partial => ''castingcomment_form'' %> app/controllers/castingcomments_controller.rb def create @castingcomment = Castingcomment.new( params[:castingcomment] ) if @castingcomment.save redirect_to :controller => "castings", :action => "show", :id => @castingcomment.casting_id else # what to write here ? end end The problem: When the form validates it all works, but if create goes to a error what to write there ? I need to render the same page (views/casting/ show.html.erb) again to show the error to the user. Please advice me, i have been looking at this for hours. /Niklas. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 13 Jan 2011, at 05:46, Niklas Nson <niklasnson-5ZBJkHaGu7EwFerOooGFRg@public.gmane.org> wrote:> > The problem: > > When the form validates it all works, but if create goes to a error > what to write there ? I need to render the same page (views/casting/ > show.html.erb) again to show the error to the user. >Call the render method (there are loads of ways you can call it. I''d expect this approach to be covered by almost any "write a something app in 5 minutes" type tutorial Fred> Please advice me, i have been looking at this for hours. > > /Niklas. > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
In the create action, that typically ends up being `render :action => :new` Garrett Lancaster> ------------------------------------------------------------------------ > > Frederick Cheung <mailto:frederick.cheung-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > January 13, 2011 2:41 AM > > > On 13 Jan 2011, at 05:46, Niklas Nson<niklasnson-5ZBJkHaGu7EwFerOooGFRg@public.gmane.org> wrote: > >> The problem: >> >> When the form validates it all works, but if create goes to a error >> what to write there ? I need to render the same page (views/casting/ >> show.html.erb) again to show the error to the user. >> > Call the render method (there are loads of ways you can call it. I''d expect this approach to be covered by almost any "write a something app in 5 minutes" type tutorial > > Fred > >> Please advice me, i have been looking at this for hours. >> >> /Niklas. >> >> -- >> 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. >> > > ------------------------------------------------------------------------ > > Niklas Nson <mailto:niklasnson-5ZBJkHaGu7EwFerOooGFRg@public.gmane.org> > January 12, 2011 11:46 PM > > > Background: > > On my application users can post Castings [class Casting] now i want > other users to be abel to post Comments on the Castings > [Castingcomment]. > > Approach: > > views/castings/show.html.erb '' > > <%= render :partial => ''castingcomment_form'' %> > > app/controllers/castingcomments_controller.rb > > def create > @castingcomment = Castingcomment.new( params[:castingcomment] ) > if @castingcomment.save > redirect_to :controller => "castings", :action => "show", :id => > @castingcomment.casting_id > else > # what to write here ? > end > end > > The problem: > > When the form validates it all works, but if create goes to a error > what to write there ? I need to render the same page (views/casting/ > show.html.erb) again to show the error to the user. > > Please advice me, i have been looking at this for hours. > > /Niklas. >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Looks like you have Casting has_many :comments, and you have a comment form on your Casting show page. If so, then you just need to render your casting show page. But this requires you to supply the Casting show page the @casting variable in your controller. ... else @casting = Casting.find(@castingcomment.casting_id) render ''casting/show.html.erb'' end I would recommend that you not have a Castingcomment class. Say you need comments for different models, then you could have Anothermodelcomment class, etc. Consider having just a Comment model and create polymorphic associations from that model. Here''s a refernce http://www.arailsdemo.com/posts/20 Here is some background for that post http://www.arailsdemo.com/posts/16 -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Thanks, will have a look @ polymorphic associations, looks like what i want! If i can get it to work. Thanks again! /Niklas. On 13 Jan, 18:15, "Arailsdemo A." <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Looks like you have Casting has_many :comments, and you have a comment > form on your Casting show page. If so, then you just need to render your > casting show page. But this requires you to supply the Casting show page > the @casting variable in your controller. > > ... > else > @casting = Casting.find(@castingcomment.casting_id) > render ''casting/show.html.erb'' > end > > I would recommend that you not have a Castingcomment class. Say you need > comments for different models, then you could have Anothermodelcomment > class, etc. Consider having just a Comment model and create polymorphic > associations from that model. > > Here''s a referncehttp://www.arailsdemo.com/posts/20 > > Here is some background for that posthttp://www.arailsdemo.com/posts/16 > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.