I'm trying to use gon. I'm able to use gon.variable_name
in my controllers but when I write gon.watch.variable_name
it throws error:
undefined method `variable_name=' for nil:NilClass
I've included gon
in my application.html.erb
as:
<%= include_gon(:init => true) %>
What is wrong here?
Update: Even in the wiki, it says same way to use it
Did you try:
<%= Gon::Base.render_data %>
instead of:
<%= include_gon(:init => true) %>
?
In your rails file, it should be formatted as gon.watch.variable_name, but not in your .js file.
In your .js file, it should be formatted like so:
gon.watch('variable_name', function() {});
If for example you were getting a list of tasks from your TasksController, you would put:
gon.watch.tasks = Task.all
And in your .js file:
gon.watch('tasks', function(tasks) {
//do something with tasks
});