Reputation: 564
How I can integrate ruby variable into a js file. I would like to render a partial relative to the current step of registration of my User. But I can't succeed it, Rails do not translate @flat.current_step in his value (which is a integer). Any ideas ?
$('.flats').replaceWith("<%= j render partial: 'flats/steps/step#{@flat.current_step}' %>");
Error
ActionView::Template::Error (Missing partial flats/steps/_step#{@flat.current_step}
Upvotes: 1
Views: 54
Reputation: 7779
Ruby does not interpolate the #{}
when wrapped in single quotes. Change your call to:
$('.flats').replaceWith('<%= j render partial: "flats/steps/step#{@flat.current_step}" %>');
Upvotes: 4