Note that there are some explanatory texts on larger screens.

plurals
  1. POHw do i render a partial in rails 3.0 using ajax, on radio button select?
    primarykey
    data
    text
    <p>I try a bit of ajax first time but did not get success, i want to render a partial on radio button select using ajax, here is my code :</p> <p>My script.js:</p> <pre><code>$(document).ready(function(){ $.ajax({ url : "/income_vouchers/income_voucher_partial?$('form input[type=radio]:checked').val()="+$('form input[type=radio]:checked').val(), type: "GET", data: { type: $('form input[type=radio]:checked').val() } }); }); </code></pre> <p>income_voucher.js.erb</p> <pre><code>$("#payment_mode").append(' &lt;% if params[:type]== 'cheque' %&gt; &lt;%= escape_javascript render :partial =&gt; "cheque" %&gt; &lt;% elsif params[:type]=='card' %&gt; &lt;%= escape_javascript render :partial =&gt; "card" %&gt; &lt;% elsif params[:type]=='ibank'%&gt; &lt;%= escape_javascript render :partial =&gt; "ibank" %&gt; &lt;% else params[:type] == 'cash' %&gt; &lt;% end %&gt; '); </code></pre> <p>My from:</p> <pre><code>&lt;script type="text/javascript" src="/javascripts/voucher.js"&gt;&lt;/script&gt; &lt;%= form_for(@income_voucher) do |f| %&gt; &lt;%= render 'shared/form_error', :object =&gt; @income_voucher %&gt; &lt;div &gt; &lt;%= radio_button_tag :transaction_type,'cash', :checked =&gt; true %&gt; &lt;%= f.label :transaction_type, "Cash", :value =&gt; "cash" %&gt; &lt;%= radio_button_tag :transaction_type,'cheque' %&gt; &lt;%= f.label :transaction_type, "Cheque", :value =&gt; "cheque" %&gt; &lt;%= radio_button_tag :transaction_type,'card'%&gt; &lt;%= f.label :transaction_type, "Card", :value =&gt; "card" %&gt; &lt;%= radio_button_tag :transaction_type,'ibank'%&gt; &lt;%= f.label :transaction_type, "Internet Banking", :value =&gt; "ibank" %&gt; &lt;/div&gt; &lt;div id = "payment_mode"&gt; &lt;% if params[:type]== "cheque" %&gt; &lt;%= render :partial =&gt; "cheque", :f =&gt; f %&gt; &lt;% elsif params[:type]=='card' %&gt; &lt;%= render :partial =&gt; "card", :f =&gt; f %&gt; &lt;% elseif params[:type] == 'ibank'%&gt; &lt;%= render :partial =&gt; "ibank", :f =&gt; f %&gt; &lt;% else params[:type] == 'cash' %&gt; &lt;% end %&gt; &lt;/div&gt; &lt;%= f.submit %&gt; &lt;% end %&gt; </code></pre> <p>and here is my controller method:</p> <pre><code> class IncomeVouchersController &lt; ApplicationController def new @income_voucher = IncomeVoucher.new @invoices = current_company.invoices @income_voucher.build_payment_mode respond_to do |format| format.html # new.html.erb format.xml { render :xml =&gt; @income_voucher } end end def create @income_voucher = IncomeVoucher.new(params[:income_voucher]) transaction_type = params[:transaction_type] payment_mode = nil if transaction_type == 'cheque' payment = ChequePayment.new(params[:cheque_payment]) payment.amount = @income_voucher.amount elsif transaction_type == 'card' payment = CardPayment.new(params[:card_payment]) payment.amount = @income_voucher.amount elsif transaction_type == 'ibank' payment = InternetBankingPayment.new(params[:internet_banking_payment]) payment.amount = @income_voucher.amount else payment = CashPayment.new payment.amount = @income_voucher.amount end payment_mode = PaymentMode.new payment_mode.transactionable = payment @income_voucher.payment_mode = payment_mode respond_to do |format| if @income_voucher.save format.html { redirect_to(@income_voucher, :notice =&gt; 'Income voucher was successfully created.') } format.xml { render :xml =&gt; @income_voucher, :status =&gt; :created, :location =&gt; @income_voucher } else format.html { render :action =&gt; "new" } format.xml { render :xml =&gt; @income_voucher.errors, :status =&gt; :unprocessable_entity } end end def income_voucher_partial @payment_mode = PaymentMode.new(params[:payment_mode]) end end </code></pre> <p>i can see my view form but when select a radio button nothing is rende. Any help would be appreciated</p>
    singulars
    1. This table or related slice is empty.
    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