簡體   English   中英

Gon看着沒有工作Rails 4

[英]Gon watch not working Rails 4

我正在嘗試使用gon 我可以在我的控制器中使用gon.variable_name但是當我寫gon.watch.variable_name會拋出錯誤:

undefined method `variable_name=' for nil:NilClass  

我在我的application.html.erb包含了gon

<%= include_gon(:init => true) %>  

這有什么不對?

更新:即使在維基中 ,也會同樣的方式使用它

你試過了嗎:

<%= Gon::Base.render_data %>

代替:

<%= include_gon(:init => true) %>

在rails文件中,它應格式化為gon.watch.variable_name,但不能格式化為.js文件。

在.js文件中,它的格式應如下:

gon.watch('variable_name', function() {});

例如,如果您從TasksController獲取任務列表,則應該:

gon.watch.tasks = Task.all

在你的.js文件中:

gon.watch('tasks', function(tasks) {
  //do something with tasks
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM