ruby - Check whether the check-box is checked or not using Rails 3 -
i have check-box inside form.i need if user checked check-box action execute , check check-box status whether checked or not using rails 3.my form given below.
paym.html.erb:
<%= form_for :add_payment,:url => {:action => 'add_payment' },remote: true |f| %> <table class="table table-bordered"> <colgroup> <col class="col-md-1 col-sm-1"> <col class="col-md-1 col-sm-1"> <col class="col-md-3 col-sm-3"> <col class="col-md-3 col-sm-3"> <col class="col-md-4 col-sm-4"> </colgroup> <thead> <tr> <th class="text-center"><input type="checkbox"></th> <th class="text-center">sl. no</th> <th class="text-center">date</th> <th class="text-center">receipt no.</th> <th class="text-center">amount</th> </tr> </thead> <tbody> <% @result.each |r| %> <tr> <th class="text-center"><%= check_box_tag :check_value,nil,:id => "checkbox1-1" %></th> <td class="text-center"><%= r.id %></td> <td class="text-center"><%= r.c_date %></td> <td class="text-center"><%= r.receipt_no %></td> <td class="text-center"><i class="fa fa-rupee"></i><%= r.v_amount %></td> </tr> <% end %> </tbody> </table> <% end %>
paym_controller.rb:
class paymentscontroller < applicationcontroller def add_payment end end
here have table value .i need when user checked box 1-it check whether check box checked or not,2-if checked table value corresponding check-box
.please me.
<%= check_box_tag :check_value,nil,:id => "checkbox1-1" %>
you had pass nil
value instead pass object r
like:
<%= check_box_tag :check_value, :value => r, :id => "checkbox1-1" %>
now using jquery can check if checkbox checked retrieve it's value. in form of value particular object r
, can fetch required data.
i hope may helps :)
Comments
Post a Comment