Hello, Please check my code for creating feedbacks on my application. Code is simple, because I''m new to RoR and only studying(It''s working but i''m not sure about method render :action=>:index, because somewhere i read that better to use redirect_to method): class Leave::FeedbackController < ApplicationController layout ''base'' def index @feedback = Feedback.new end def theend begin @feedback = Feedback.new(params[:feedback]) @feedback.added_at = Time.now if @feedback.save flash[:notice] = "Feedback succesfully created" return else render :action => :index end rescue Exception => ex logger.debug "Error while adding new feedback, ex=" + ex.to_s end end end <table> <tr> <td> <% form_for :feedback, :url=> {:action => :theend} do |form|%> <p> <%= error_messages_for ''feedback'' %> </p> <p> <label for="feedback_author">Author:</label> <br/> <%= form.text_field :author, :size => 20 %> <br/> <label for="feedback_feedback_text">Feedback text:</label> <br/> <%= form.text_area :feedback_text, :size=>''40x10''%> <br/> <label for="feedback_email">Email:</label> <br/> <%= form.text_field :email, :size => 20 %> <br/> <br/> <%= submit_tag "Send feedback" %> </p> <% 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 -~----------~----~----~----~------~----~------~--~---
On 7 Oct 2007, at 16:16, Igor K. wrote:> > Hello, > > Please check my code for creating feedbacks on my application. > Code is simple, because I''m new to RoR and only studying(It''s working > but i''m not sure about method render :action=>:index, because > somewhere > i read that better to use redirect_to method):render :action is not better than redirect_to, it''s just different. render makes rails use a different template, redirect_to makes the browser resubmit a request to the specified url. Both have their place, although it is true that there are cases where one is preferable than they other. One of the cases where you do want to use render is when validation of some user submitted form has failed (in particular if you did redirect_to :action => :index then you''d lose all the stuff the user submitted) 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 -~----------~----~----~----~------~----~------~--~---
> One of the cases where you do want to use render is when validation > of some user submitted form has failed (in particular if you did > redirect_to :action => :index then you''d lose all the stuff the user > submitted)Yes I noticed that i used redirect_to i loose my validation errors. Finally do you think this code good enough? because i only starts from feedback model and i still need to implement 10 models more in this way. Thanks -- 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 -~----------~----~----~----~------~----~------~--~---
On 7 Oct 2007, at 17:05, Igor K. wrote:> > >> One of the cases where you do want to use render is when validation >> of some user submitted form has failed (in particular if you did >> redirect_to :action => :index then you''d lose all the stuff the user >> submitted) > > Yes I noticed that i used redirect_to i loose my validation errors. > > Finally do you think this code good enough? because i only starts from > feedback model and i still need to implement 10 models more in this > way. >It''s a fairly standard pattern Fred> Thanks > > > -- > 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 -~----------~----~----~----~------~----~------~--~---