I have several orders that are being updated in an internal data entry app. I start by going from an order to pop-up form that allows a user to select items to add to a field in the order. The pop-up form contains 2 partials for drag and drop functionality from AWD. The user starts by selecting a category in a drop down list. Then on select, the first partial is filled with the list of options. The user can then drag and drop from the first partial to the second. Now, my question is how to keep the original order id available to the partials at all times. Right now I have a global variable set in the action when the page loads, but I''m guessing that this might not be the best way to do this. The first partial needs the order id so that it can look up which items have already been selected so it doesn''t include those in the option to select. The second partial displays all of the items that have been selected. Hope this makes sense. 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 -~----------~----~----~----~------~----~------~--~---
Becca Girl wrote:> Right now I have a global variable set in the action when the page > loads, but I''m guessing that this might not be the best way to do this. > The first partial needs the order id so that it can look up which items > have already been selected so it doesn''t include those in the option to > select. The second partial displays all of the items that have been > selected.Use render :partial => ''foo'', :locals => { :@bar => bar }. You can call that from Ajax handlers, and ViewTests, too. The :0 is a trick that allows _foo.rhtml to check if the variable exists at all: if @bar ... Without that, no element of :locals would be optional, because an if bar on a non-existent bar is a syntax error, and checking defined? all the time is odious! -- Phlip http://www.oreillynet.com/onlamp/blog/2007/07/assert_latest_and_greatest.html --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Becca Girl
2008-Apr-28 16:41 UTC
Re: Best way to pass ID variable to partials - global var??
Phlip wrote:> Use render :partial => ''foo'', :locals => { :@bar => bar }. > > You can call that from Ajax handlers, and ViewTests, too. > > The :0 is a trick that allows _foo.rhtml to check if the variable exists > at all: > > if @bar ... > > Without that, no element of :locals would be optional, because an if bar > on a > non-existent bar is a syntax error, and checking defined? all the time > is odious! >I''m not able to make that work. The id of the order is selected in action 1 which then calls a partial. Once the partial is rendered, that partial calls action 2 - this creates the drag and drop. Action 2 needs to be aware of the order id to make it available to action 3 when the partials are refreshed with the new lists for drag and drop. I think that I''m missing something to make this happen or I have the locals set incorrectly. I also need to keep in mind that multiple orders will be updated throughout the process so it''s not a situation where I can set it and forget it. Are locals still the best way to pass the id to the other actions or do I need to set up a method in the model that somehow retains the order id? 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 -~----------~----~----~----~------~----~------~--~---
Roger Pack
2008-Apr-28 18:35 UTC
Re: Best way to pass ID variable to partials - global var??
> Are locals still the best way to pass the id to the other actions or do > I need to set up a method in the model that somehow retains the order > id?Fix locals or pass things around as instance variables @id = x --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Becca Girl
2008-Apr-28 23:47 UTC
Re: Best way to pass ID variable to partials - global var??
Roger Pack wrote:> Fix locals or pass things around as instance variables > @id = xI''m still new at this so I apologize for asking such an elementary question. This is what I have and maybe someone can help me figure out where I''m going wrong with passing variables. For this example, let''s say I''m adding fruit to an order. The user will start on an order page, click on a link that opens a pop-up for fruit. The pop up gets the order ID from the page the opened the pop up. The pop up contains a select box and 2 partials with drag and drop functionality. Let''s say the select box let''s you select by color of fruit. I left off some of the code to shorten the post, but I explained what I''m looking for in the actions. #controller def get_order @order = Order.find(params[:id]) end def get_fruit_list @fruit_list = Items.find_all_by_color(params[:color]) render :update do |page| page.replace_html ''fruit_list'', :partial => ''fruit_list'', :locals => {:order_id => @order.id } end end get_fruit_selected #order number needed to add the fruit to the order @order = Order.find(params[:order_id]) #code here --> fruit is saved to the order list #code here --> both partials are rendered to reflect the added fruit end So what I''m missing here is how to pass that ID number from get_order to get_fruit selected. 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 -~----------~----~----~----~------~----~------~--~---
Roger Pack
2008-Apr-29 03:05 UTC
Re: Best way to pass ID variable to partials - global var??
store it in the session or pass it as a parameter to your popup, I''d guess. -R On Mon, Apr 28, 2008 at 5:47 PM, Becca Girl <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Roger Pack wrote: > > > Fix locals or pass things around as instance variables > > @id = x > > > I''m still new at this so I apologize for asking such an elementary > question. > > This is what I have and maybe someone can help me figure out where I''m > going wrong with passing variables. > > For this example, let''s say I''m adding fruit to an order. The user will > start on an order page, click on a link that opens a pop-up for fruit. > The pop up gets the order ID from the page the opened the pop up. The > pop up contains a select box and 2 partials with drag and drop > functionality. Let''s say the select box let''s you select by color of > fruit. I left off some of the code to shorten the post, but I explained > what I''m looking for in the actions. > > > #controller > > def get_order > @order = Order.find(params[:id]) > end > > def get_fruit_list > @fruit_list = Items.find_all_by_color(params[:color]) > > render :update do |page| > page.replace_html ''fruit_list'', :partial => ''fruit_list'', :locals => > {:order_id => @order.id } > end > end > > > get_fruit_selected > #order number needed to add the fruit to the order > @order = Order.find(params[:order_id]) > > #code here --> fruit is saved to the order list > #code here --> both partials are rendered to reflect the added fruit > end > > > So what I''m missing here is how to pass that ID number from get_order to > get_fruit selected. > > 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 -~----------~----~----~----~------~----~------~--~---