Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/59.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails coffeescript模板中出现意外的“逻辑”_Ruby On Rails_View_Ruby On Rails 3.1_Coffeescript - Fatal编程技术网

Ruby on rails coffeescript模板中出现意外的“逻辑”

Ruby on rails coffeescript模板中出现意外的“逻辑”,ruby-on-rails,view,ruby-on-rails-3.1,coffeescript,Ruby On Rails,View,Ruby On Rails 3.1,Coffeescript,将此代码放在.js.coffee部分类型的视图中,它将作为视图而不是资产呈现: <% if @followed_car_ids.present? %> for car_id_and_path in <%= @followed_car_ids_and_paths.to_json %> toggle_follow(car_id_and_path[0], true, car_id_and_path[1]) <% end %> 请注意,在视图中放置地图或收集并不

将此代码放在.js.coffee部分类型的视图中,它将作为视图而不是资产呈现:

<% if @followed_car_ids.present? %>
for car_id_and_path in <%= @followed_car_ids_and_paths.to_json %>
  toggle_follow(car_id_and_path[0], true, car_id_and_path[1])
<% end %>
请注意,在视图中放置地图或收集并不重要。如果我把一个简单的字符串而不是url\u放在

它给出了以下错误:

ActionView::Template::Error (Error: Parse error on line 1: Unexpected 'LOGIC'):
    1: <% if @followed_car_ids.present? %>
    2: for car_id_and_path in <%= @followed_car_ids_and_paths.to_json %>
    3:   toggle_follow(car_id_and_path[0], true, car_id_and_path[1])
    4: <% end %>
  app/views/general_ajax/_update_followed_cars.js.coffee:1:in `_app_views_general_ajax__update_followed_cars_js_coffee__3478461849674996439_70355260673980'
如果我使用的平面阵列未与map一起加倍,则不会发生错误:

for car_id_and_path in <%= @followed_car_ids %>

在我的coffeescript文件中使用to_json将实例变量解析为json时,我遇到了同样的问题

我通过在行中添加html_safe解决了此问题:


@instance_var.to_json.html_safe

在我的coffeescript文件中使用to_json将实例变量解析为json时,我遇到了同样的问题

我通过在行中添加html_safe解决了此问题:


@instance_var.to_json.html_safe

我认为这很有意义!我会在有时间的时候尝试一下,同时我正在使用一种更基本的方法…谢谢!很高兴我终于找到了。我认为这是有道理的!我会在有时间的时候尝试一下,同时我正在使用一种更基本的方法…谢谢!很高兴我终于找到了安全的
for car_id_and_path in [1,2,3] <% @followed_car_ids_and_paths.to_json %>
for car_id_and_path in <%= @followed_car_ids %>
for car_id_and_path in [[1, 'a'],[2, 'b'],[3, 'c']]