Aaron Taddiken

Joined

320 Experience
2 Lessons Completed
0 Questions Solved

Activity

Ok, yes you are correct. I got a syntax error which was easliy fixed with single quotes around options = $(thick_dicts).filter("optgroup[label=' + tree + ']").html();

However, now once a tree is selected there are no thick_dict options showing up in the list. They do still show in the console.

Hi Chris,

Actually I take that back...Looks like it is not scoping in the logs. It has all the options.

console.log(options):

    slabs.self-c2aef00….js?body=1:3 <option value=""></option>
<optgroup label="American Elm"><option selected="selected" value="6">8/4</option>
<option value="8">4/4</option>
<option value="9">6/4</option>
<option value="16">11/4</option></optgroup><optgroup label="Black Locust"><option value="10">12/4</option></optgroup><optgroup label="Black Walnut  "></optgroup><optgroup label="Boxelder"></optgroup><optgroup label="Butternut"><option value="7">11/4</option></optgroup><optgroup label="Catalpa"><option value="14">4/4</option></optgroup><optgroup label="Cedar"></optgroup><optgroup label="English Elm"></optgroup><optgroup label="Hackberry"></optgroup><optgroup label="Honeylocust"></optgroup><optgroup label="Mulberry "><option value="11">4/4</option>
<option value="12">12/4</option></optgroup><optgroup label="Siberian Elm"><option value="15">10/4</option></optgroup><optgroup label="Silver maple"><option value="13">8/4</option></optgroup><optgroup label="Tree of Heaven"><option value="17">8/4</option></optgroup>

I am trying to scope a form selection list to from another select box selection. The select box groups the options correctly in the dropdown. Everything checks out in the console but it still does not scope.

app/models/slab.rb

      class Slab < ActiveRecord::Base

        ...
         belongs_to :tree
        ...
        belongs_to :thick_dict
        ...
        end

app/models/tree.rb

    class Tree < ActiveRecord::Base
    has_many :thick_dicts
    has_many :slabs, dependent: :restrict_with_exception
    end

app/models/thick_dict.rb

    class ThickDict < ActiveRecord::Base
    ...
    belongs_to :tree
    has_many :slabs, dependent: :restrict_with_exception
    end

app/views/slabs/_form.html.erb

        <%= f.grouped_collection_select :thick_dict_id, Tree.order(:name).where(client_id: current_user.client), :thick_dicts, :name, :id, :display_name, include_blank: true %><br>

apps/assets/javascript/slabs.js

jQuery(function() {
  var thick_dicts = $('#slab_thick_dict_id').html();
  console.log(thick_dicts);
  return $('#slab_tree_id').change(function() {
    var tree, options;
    tree = $('#slab_tree_id :selected').text();
    options = $(thick_dicts).filter("optgroup[label=" + tree + "]").html();
    console.log(options);
    if (options) {
      return $('#slab_thick_dict_id').html(options);
    } else {
      return $('#slab_thick_dict_id').empty();
    }
  })
});

Posted in Exporting Records To CSV Discussion

Hahaha
Exactly!

Posted in Exporting Records To CSV Discussion

WOW!
Can't thank you enough Chris!
It's working :)
You Rock!

Posted in Exporting Records To CSV Discussion

Oh man! I'm almost getting it...
That's really helpful BUT I'm still lost on the model piece...

Service.rb
def self.to_csv
attributes = %w{SomeColumn Date}
CSV.generate(headers: true) do |csv|
csv << attributes
all.each do |service|
csv << [service.name, service.date]
end
end
end

I don't get how this gets repeated for new queries...
Thanks Again!

Posted in Exporting Records To CSV Discussion

Thank you for the lightening fast reply.
But what I mean is not simultaneous downloads but just single requests from multiple queries.
I have a dashboard on an index page breaking down the data into palatable user friendly chunks and want to have a download csv button for each one. I'm sure I'm way over complicating it but I literally can't conceptualize how to move beyond the one exactly like in your example above.
Thanks!

Posted in Exporting Records To CSV Discussion

Very well done.
Can you guide me in the direction of making multiple CSV exports on the same model/controller. I can't seem to figure out how to do more than one query-export...