简体   繁体   中英

Rails - partial locals not working

When I try to render a partial in an AJAX response it's saying undefined local variable or method 'campaign'

In create.js.erb :

$("#progress").html("<%= j(render 'campaigns/progress_bars', locals: {campaign: @bid.campaign}) %>");

And then whenever I refer to it in the partial I just use something like:

<%= campaign.option_1 unless campaign.blank? %>

I use this partial elsewhere in the app and it works just fine.

Turns out it's necessary to use the partial keyword in this scenario:

$("#progress").html("<%= j(render partial: 'campaigns/progress_bars', locals: {campaign: @bid.campaign}) %>");

I'm still not sure when and why that is necessary but it was the fix for this problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM