【发布时间】:2018-02-03 22:11:10
【问题描述】:
我在后端有控制器,并且希望在(咖啡)脚本中包含变量,这些变量与模型一起发送到浏览器 - 但得到了未定义的值。我做错了什么?我可以在模型中看到值。
控制器:
def show
@article = Article.find(params[:id])
end
脚本 article.coffee.erb:
$ ->
$('#sendComment').click ->
id = "#{@article.id}"
console.log(id)
在模型中:
%p
%strong Title:
#id
= @article.id
%p
%strong Title:
= @article.title
【问题讨论】:
-
article.coffee.erb 在哪里以及如何加载?
#sendComment在哪里?而不是 mockup 告诉我们你在哪里渲染 HAML? -
@Leito 它在加载时已经在页面上 - rails 将它添加到脚本中
标签: javascript ruby-on-rails ruby coffeescript