samedi 24 juin 2017

How make Jquery_chained.js choose the id in Rails?

After added the jquery_chained.js and setup everything works fine, but on the save the eletronic_id inside container table still nil.

Someone know why and how to fix it?

I've tried to change on the js to call to see if fix, but did not worked. $('select#eletronic_name').chainedTO('select#block_name');

http://ift.tt/1wGUPXx

 model container

        belons_to :block
        belongs_to :eletronic

        end



    $(document).ready(function(){

       $('#eletronic').chained('#block');

    }); 

    ContainersController

     # creating data arrays for selects
        @blocks = Block.all
        @blocks_for_dropdown = []
        @blocks.each do |i|
          @blocks_for_dropdown << [i.category, i.id]
        end

    # creating data arrays for selects
        @eletronics = Eletronic.all
        @eletronics_for_dropdown = []
        @eletronics.each do |i|
        @eletronics_for_dropdown << [i.item, i.id, {class: i.block.id}]
        end



    end




container new.html.erb

  <%= select("block", "name", options_for_select(@blocks_for_dropdown), {prompt: 'Select'}, {class: 'chained-select', :id => 'block'}) %>



  <%= select("eletronic", "name", options_for_select(@eletronics_for_dropdown), {prompt: 'Select'}, {class: 'chained-select', :id =>'eletronic'}) %>

Aucun commentaire:

Enregistrer un commentaire