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.
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!
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?
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