我如何写一个jquery js.Erb为link_to同时提供HTML和ruby输出:remote =>在rails 3

How do I write a jquery js.erb to have both html and ruby output for a link_to :remote => in rails 3?

本文关键字:remote 输出 ruby HTML rails jquery js 何写一 Erb to link      更新时间:2023-09-26

我有以下在我的js。Erb文件,但它不执行ruby代码:

4 //Update the number of followers
  5 $('.follow-count').html("#{@followers_count} following")

混合ruby(和从控制器访问的东西)和常规文本的正确方法是什么?

js.erb文件就像您的html.erb文件一样工作。您需要使用<%= %>标签代替:

 $('.follow-count').html("<%= @followers_count %> following")