First you need to see that the input field has changed to see it. So, assuming:
- The storage selector has a storage identifier
- The store selector has a "store" identifier as its value
... you can put this in your storage.coffee.js
file:
jQuery -> $('select#storage').change -> storage_id = $('option:selected',this).val() $.get 'storages/' +storage_id+ '/orders.js'
Then, assuming that Orders are nested, if your OrdersController looks like this:
OrdersController < ApplicationController def index @storage = Storage.find(params[:storage_id]) @orders = @storage.orders end end
... and if you have a partial app/views/orders/_order.html.erb
...
... and if your page has a div#orders
in which you want orders to fall in ...
... then you should make the file app/views/orders/index.js.erb
as follows:
$('div#orders').html('<%= escape_javascript(render @orders) %>');
This should make a partial copy for each instance of orders belonging to this repository and add it to dom after the repository selector.
What happens: when you change the selection menu, it starts a js GET request in the order index for this store. Then this request will automatically try to serve the index.js page, and the instance variables set in the controller are available for this view. Js in this view will be executed after any interpolated ruby ββis inserted, so you can use the rail functions (e.g. render @orders
) and then output those that are injected into dom via $('div#orders').html('your rendered orders will be inserted in here by rails')
.
It is clear that you will need to configure it to fit your page, I just guess what elements of your page cause, etc., but this basic concept should work fine. Let me know if you have any questions.
source share