Note that there are some explanatory texts on larger screens.

plurals
  1. POCheckbox and Ajax
    primarykey
    data
    text
    <p>I'm creating a Rails 3.1 Ruby 1.9.2 web application. I've a model named BulkWarehouse and I have a view that shows all BulkWarehouse objects on my db. This is my controller:</p> <pre><code>def index @bulk_all = BulkWarehouse.all @bulk_out = Array.new end </code></pre> <p>and this is my view:</p> <pre><code> &lt;%= form_for :warehouse, :url =&gt; warehouses_path, :html =&gt; { :class =&gt; :form } do |f| -%&gt; &lt;div class="content"&gt; &lt;h2 class="title"&gt;&lt;%= t("web-app-theme.all", :default =&gt; "Prodotti") %&gt; da caricare a sistema&lt;/h2&gt; &lt;%= f.fields_for 'hardware' do |hw|%&gt; &lt;div class="group"&gt; &lt;%= hw.label 'brand', t("activerecord.attributes.warehouse.hardware.brand_id", :default =&gt; "Marca"), :class =&gt; :label %&gt; &lt;%= hw.select 'brand_id', options_for_select(@brands),{:include_blank =&gt; true}, :class =&gt; 'text_field' %&gt; &lt;span class="description"&gt;Marca dell'hardware&lt;/span&gt; &lt;/div&gt; &lt;div class="group"&gt; &lt;%= hw.label 'model', t("activerecord.attributes.warehouse.hardware.brand_id", :default =&gt; "Modello"), :class =&gt; :label %&gt; &lt;%= hw.select 'model', options_for_select(@hardwares),{:include_blank =&gt; true}, :class =&gt; 'text_field' %&gt; &lt;span class="description"&gt;Marca dell'hardware&lt;/span&gt; &lt;/div&gt; &lt;% end %&gt; &lt;div class="group"&gt; &lt;%= f.label 'state', t("activerecord.attributes.warehouse.state_id", :default =&gt; "State"), :class =&gt; :label %&gt; &lt;%= f.select('state_id', @states,{:include_blank =&gt; true}, :class =&gt;'text_field') %&gt; &lt;span class="description"&gt;In che stato si trova ?&lt;/span&gt; &lt;/div&gt; &lt;div class="group"&gt; &lt;%= f.label 'position', t("activerecord.attributes.warehouse.registry_to_id", :default =&gt; "Magazzino fisico"), :class =&gt; :label %&gt; &lt;%= f.select('position_id', @positions,{:include_blank =&gt; false}, :class =&gt;'text_field') %&gt; &lt;/div&gt; &lt;div class="group"&gt; &lt;%= f.label 'logicalwarehouse', t("activerecord.attributes.warehouse.logicalwarehouse_id", :default =&gt; "Magazzino Logico"), :class =&gt; :label %&gt; &lt;%= f.select('logicalwarehouse_id', @logicalwarehouses,{:include_blank =&gt; false}, :class =&gt;'text_field',:order =&gt;:id) %&gt; &lt;span class="description"&gt;In quale magazzino logico è stato spostato?&lt;/span&gt; &lt;/div&gt; &lt;div class="group"&gt; &lt;%= f.label 'extra', t("activerecord.attributes.warehouse.extra_id", :default =&gt; "Extra"), :class =&gt; :label %&gt; &lt;%= f.select('extra_id', @extras,{:include_blank =&gt; false}, :class =&gt;'text_field') %&gt; &lt;span class="description"&gt;Campo Extra&lt;/span&gt; &lt;/div&gt; &lt;% end -%&gt; &lt;table class="table"&gt; &lt;tr&gt; &lt;th class="first"&gt;Asset&lt;/th&gt; &lt;th&gt; &lt;%= t("activerecord.attributes.logicalwarehouse.name", :default =&gt; t("activerecord.labels.name", :default =&gt; "Seriale")) %&gt; &lt;/th&gt; &lt;th class="last"&gt;&amp;nbsp;&lt;/th&gt; &lt;/tr&gt; &lt;/tr&gt; &lt;% @bulk_objects.each do |bulk_warehouse| bulk_error = @wh_errors[:"bulk_warehouse#{@count}"] if @wh_errors -%&gt; &lt;tr class="&lt;%= cycle("odd", "even") %&gt;"&gt; &lt;%= hidden_field_tag("bulk_warehouse_id#{@count}",bulk_warehouse.id) %&gt; &lt;td&gt;&lt;%= text_field_tag("bulk_warehouse_serial#{@count}", bulk_warehouse.serial, :disabled =&gt; true) %&gt;&lt;/td&gt; &lt;td&gt;&lt;%= text_field_tag("bulk_warehouse_asset#{@count}", bulk_warehouse.asset, :disabled =&gt; true)%&gt;&lt;/td&gt; &lt;td&gt;&lt;%= check_box_tag "enable_record#{@count}",1,false,{:onclick =&gt; "bulk_warehouse_serial#{@count}.disabled = bulk_warehouse_asset#{@count}.disabled = !this.checked;"}%&gt;&lt;/td&gt; &lt;td class="last"&gt; &lt;%= link_to "#{t("web-app-theme.delete", :default =&gt; "Delete")}", bulk_warehouse_path(bulk_warehouse), :method =&gt; :delete, :confirm =&gt; "#{t("web-app-theme.confirm", :default =&gt; "Are you sure?")}" %&gt; &lt;/td&gt; &lt;td&gt;&lt;div class="fieldWithErrors" style="color=red"&gt;&lt;%= bulk_error -%&gt;&lt;/div&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/div&gt; &lt;% @count = @count +1 end %&gt; &lt;/table&gt; &lt;script&gt; $(document).ready(function() { $('.pagination a').attr('data-remote', 'true'); }); &lt;/script&gt; &lt;%= will_paginate @bulk_objects, :params=&gt;{:id=&gt;params[:id]} %&gt; </code></pre> <p>As you can see, there' s a checkbox tag for each bulk_warehouse item contained in @bulk_objects. Now I want that when I click on a checkbox, bulk_warehouse object related to checkbox, must be append to @bulk_out array defined in controller. I know that I can do this using Jquery but I don't know how. Anyone can help me?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload