1
votes

I have multiple check box in my form ,working very good.I need to give more option to add like four chkbox then a text field related to them

my model looks like

PaymentGateway.rb

has_many :payment_rfps

has_many :rfps, :through => :payment_rfps

class PaymentRfp < ActiveRecord::Base

attr_accessible :payment_gateway_id,:rfp_id

belongs_to :payment_gateway

belongs_to :rfp end

rfp.rb

has_many :payment_rfps

has_many :payment_gateways, :through => :payment_rfps

my view part

    <div class = "lft_cms" ><b>Payment Gateways</b>
     <div class="field">
     <%= hidden_field_tag "rfp[ payment_gateway_ids][]", nil %>
       <% PaymentGateway.all.each do |payment_gateway| %>
         <%= check_box_tag "rfp[payment_gateway_ids][]",payment_gateway.id, @rfp.payment_gateway_ids.include?(payment_gateway.id), :id => dom_id(payment_gateway) %>
          <%= label_tag dom_id(payment_gateway), payment_gateway.name %><br>
<% end %>

   </div>

how can i add a text field which give additional option to fill any help appreciated.Thanks

1
Add all the extra stuff to your view, but place it all in a div that is hidden. Then unhide that div with javascript when they activate the appropriate control. - Daiku

1 Answers

0
votes

First of all, PaymentGateway.all is a bad idea. This shouldn't be there in the view but loaded from the controller in an instance variable. Please change that.

One way to do that would be to define a attribute, let us say 'additional_info':

<% PaymentGateway.all.each do |pg| %>
  <%= check_box_tag ..., onclick: "$('#{pg}_info').show(); $('#{pg}_info').siblings().hide();" %>
  ...
<% end %>

<div class="additional_infos">
  <%= f.input :gateway1_info, label: "Gateway" ... %>
</div>