Hi, I was wondering if there was any way to pass a value through the render :action in my controller. The controller calls render when fields are left blank in my form and errors need to be shown. With redirect_to :action, I am simply able to add a parameter to be passed like so: redirect_to :action => ''new'', :parameter => @form.pass_this_value However I am not able to do the same with render :action. I cannot use redirect_to since it does not display the form field errors. Is there any way around this? Or another means of retrieving a value once a view has been rendered? Thanks. -Gilles -- 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 -~----------~----~----~----~------~----~------~--~---
Try: render :action => ''new'', :locals => { :parameter => @form.pass_this_value } Jason On 9/13/06, Gilles <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > Hi, I was wondering if there was any way to pass a value through the > render :action in my controller. The controller calls render when fields > are left blank in my form and errors need to be shown. With redirect_to > :action, I am simply able to add a parameter to be passed like so: > > redirect_to :action => ''new'', :parameter => @form.pass_this_value > > However I am not able to do the same with render :action. I cannot use > redirect_to since it does not display the form field errors. Is there > any way around this? Or another means of retrieving a value once a view > has been rendered? Thanks. > > -Gilles > > -- > 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 -~----------~----~----~----~------~----~------~--~---
I tried your suggestion, Jason. I still am not getting anything passed. Maybe theres something I''m missing. -Gilles Jason Roelofs wrote:> Try: > > render :action => ''new'', :locals => { :parameter => > @form.pass_this_value } > > Jason-- 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 -~----------~----~----~----~------~----~------~--~---
> However I am not able to do the same with render :action. I cannot use > redirect_to since it does not display the form field errors. Is there > any way around this? Or another means of retrieving a value once a view > has been rendered? Thanks.Make the parameters you want available within an instance variable. @parameter = @form.pass_this_value or just access @form.pass_this_value from your view. -- 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 -~----------~----~----~----~------~----~------~--~---
The parameter is not accessible from my view. The function in the controller does not correspond with anything in the view. I have the ''create'' function that gets called when a form is submitted from the ''new'' function which has a corresponding ''new'' view. So the form in the ''new'' view is calling ''create'', then finds that some or all of the form fields are not correctly filled out in ''create''. At this time it renders :action ''new'' to display the ''new'' view with the errors displayed along with it. There is one value that I want to pass along so I can access it in the ''new'' view after the render :action has been carried out in ''create''. I pass along this value from ''new'' to ''create'' through a hidden form field, but I am unable to pass it back to ''new'' from ''create'' using the render :action. I am currently using this value to differentiate the view of ''new'' according to the value. So ''new'' would look differently based on the parameter. I hope all of this makes sense. Is there a way to implement this? -Gilles Curtis Summers wrote:> Make the parameters you want available within an instance variable. > > @parameter = @form.pass_this_value > > or just access @form.pass_this_value from your view.-- 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 -~----------~----~----~----~------~----~------~--~---
> There is one value that I want to pass along so I can access it in the > ''new'' view after the render :action has been carried out in ''create''. I > pass along this value from ''new'' to ''create'' through a hidden form > field, but I am unable to pass it back to ''new'' from ''create'' using the > render :action.If you pass a form variable (hidden or not) by submitting to the create method, then that variable will be available from params[:my_variable]. You can access params[:my_variable] from your ''new'' view if ''new'' is rendered from create. If you''re still having trouble, providing some code here would help others troubleshoot what you''re trying to do. -- 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 -~----------~----~----~----~------~----~------~--~---