0

I have the following method in my controller:

def update_fees_collection_dates_voucher
    @batch = Batch.find(params[:batch_id])
    @dates = @batch.fee_collection_dates
    render :update do |page|
        page.replace_html "fees_collection_dates", :partial =>"fees_collection_dates_voucher"
    end
end

the method calls the following partial in _fees_collection_dates_voucher.html.erb file:

<%= select  :fees_submission, :dates_id, @dates.map { |e| [e.full_name, e.id]},{:prompt => "#{t('select_fee_collection_date')}"},{:onChange => "#{remote_function( :url => {:action => "load_fees_voucher"},:with => "'date='+value+'&batch_id='+@batch.id") }"} %>

The partial makes a remote call to the load_fees_voucher method when a selection list value is selected or changed. However, I'm unable to pass the information in the @batch instance variable (from my original method) to the remote method via the partial. If I change the @batch.id to a hard-coded value in the last line (under :with) the code runs fine but not in the current format. Is there a different procedure to access instance variables in partials ? Thanks!

haanimasood
  • 77
  • 1
  • 1
  • 5

1 Answers1

0

You can use the same instance variable in the partials.

Try this,

 <%= select  :fees_submission, :dates_id, @dates.map { |e| [e.full_name, e.id]},{:prompt => "#{t('select_fee_collection_date')}"},{:onChange => "#{remote_function( :url => {:action => "load_fees_voucher"},:with => "'date='+value+'&batch_id='+#{@batch.id}") }"} %>
Nithin
  • 3,679
  • 3
  • 30
  • 55
  • That worked! Thanks :) ... can you explain a little on how this works or point me to the relevant documentation for this ? Thanks! – haanimasood Oct 15 '13 at 09:07
  • from what I have understood. While evaluating a value in a string it's necessary, for example `"i am from #{place}"` here place will be evaluated to it's value. – Nithin Oct 15 '13 at 09:17