Pregunta

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!

¿Fue útil?

Solución

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}") }"} %>
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top