Note that there are some explanatory texts on larger screens.

plurals
  1. POHw do i render a partial in rails 3.0 using ajax?
    primarykey
    data
    text
    <p>I want to use ajax in my application here is my problem :</p> <p>I have a income voucher controller and model which receives incomes from various sources. for this i have a payment_mode model with card, cheque and internet_banking payment option here is my code:</p> <p>From model: <strong>income_voucher</strong></p> <pre><code> class IncomeVoucher &lt; ActiveRecord::Base has_one :payment_mode, :foreign_key =&gt; :voucher_id end </code></pre> <p>** payment_mode:**</p> <pre><code>class PaymentMode &lt; ActiveRecord::Base belongs_to :transactionable, :polymorphic =&gt; true belongs_to :receipt_voucher end </code></pre> <p><strong>card_payment:</strong></p> <pre><code>class CardPayment &lt; ActiveRecord::Base has_one :payment_mode, :as =&gt; :transactionable, :dependent =&gt; :destroy end </code></pre> <p>similar in cheque and Internet banking model .</p> <p>My controller: <strong>income_vouchers_controller:</strong></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 end </code></pre> <p>In my form i did this:</p> <pre><code>&lt;%= render :partial =&gt; "card_payment" %&gt; &lt;%= render :partial =&gt; "cheque_payment" %&gt; &lt;%= render :partial =&gt; "internet_banking_payment" %&gt; </code></pre> <p>friend till now i am rendering my partials simply as we do in rails but now i want to do this using ajax. I hope you guy's have done this earlier. thanks </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.
    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