将ruby变量集成到js中

时间:2018-06-02 12:35:49

标签: ruby-on-rails ruby

如何将ruby变量集成到js文件中。我想对我的用户注册的当前步骤进行部分相关。 但我不能成功,Rails不会将@ flat.current_step翻译成他的值(这是一个整数)。有什么想法吗?

$('.flats').replaceWith("<%= j render partial: 'flats/steps/step#{@flat.current_step}' %>");

错误

ActionView::Template::Error (Missing partial flats/steps/_step#{@flat.current_step}

1 个答案:

答案 0 :(得分:4)

当用单引号括起来时,Ruby不会插入#{}。将您的电话改为:

$('.flats').replaceWith('<%= j render partial: "flats/steps/step#{@flat.current_step}" %>');