[英]Passing local variable to a partial in rails 2.x
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: 该方法在_fees_collection_dates_voucher.html.erb文件中调用以下部分:
<%= 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. 当选择或更改选择列表值时,局部对象将远程调用load_fees_voucher方法。 However, I'm unable to pass the information in the @batch instance variable (from my original method) to the remote method via the partial. 但是,我无法通过局部将@batch实例变量中的信息(从我的原始方法)传递到远程方法。 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. 如果我在最后一行(在:with下)将@ batch.id更改为硬编码值,则代码可以正常运行,但不是当前格式。 Is there a different procedure to access instance variables in partials ? 是否有不同的过程来访问局部变量中的实例变量? Thanks! 谢谢!
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}") }"} %>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.