Running Rails 3.2.13
Running ruby 1.9.3p392 (2013-02-22 revision 39386) [x86_64-darwin10.8.0]
gem 'activeadmin', '<= 0.6.0'
In the active_admin.rb initializer, I set it to load my js:
# To load a javascript file:
config.register_javascript 'keywords.js.coffee'
Then in my Coffeescript I have:
keywords = $('#conference_keyword_ids').html()
console.log(keywords)
Console prints out:
undefined
Then to test that I have the script right I change the script to:
keyword = 'test'
console.log(keyword)
Console prints out:
test
So to try something else, I try:
keyword = $( "title" ).html()
console.log(keyword)
And the console prints out the proper Title
Edit Conference
And:
keyword = $( ":root" ).html()
console.log(keyword)
Gives me:
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>Edit Conference</title>
<link href="/assets/active_admin.css?body=1" media="screen" rel="stylesheet" type="text/css">
<link href="/assets/active_admin/print.css?body=1" media="print" rel="stylesheet" type="text/css">
<script src="/assets/application.js" type="text/javascript">
</script>
<script src="/assets/conference_industry_keywords.js" type="text/javascript">
</script>
</head>
So I am able to retrieve a few selectors but most of them are coming up "undefined". I have used the same Coffeescript in the base Rails and all works fine.
Can anybody see anything that I am doing wrong or perhaps ActiveAdmin works differently?
Here is an example of the Coffeescript generated js:
(function() {
var title;
title = $("#conference_state_id").html();
console.log(title);
}).call(this);
I appreciate any help!
UPDATE
OK, testing in the Chrome Developers console:
I entered this into my Coffeescript:
keywords = $('#conference_keyword_ids').html()
console.log(keywords)
Console prints out:
undefined
So I add this into the console:
keywords = $('#conference_keyword_ids').html()
And I get the CORRECT output in the console:
"<optgroup label="Agriculture and Forestry"><option value="6">ag1</option></optgroup>
<optgroup label="Apparel & Clothing Congress"><option value="2">test</option>
<option value="1">test 2 testing</option></optgroup>"
So I am obviously doing something wrong. Any ideas??
Update with Examples
Here are examples. The first set I used "$ ->" and the second set I removed the "$ ->". I list the Coffescript first, jQuery second, output third, then entered into the console.
Test #1
Coffeescript entered:
$ ->
keywords = $('title').html()
console.log(keywords)
Generated jQuery:
(function() {
$(function() {
var keywords;
keywords = $('title').html();
return console.log(keywords);
});
}).call(this);
Output:
nothing output
Test #2
Coffeescript entered:
keywords = $('title').html()
console.log(keywords)
Generated jQuery:
(function() {
var keywords;
keywords = $('title').html();
console.log(keywords);
}).call(this);
Output:
Edit Conference
Test #3
In the Console:
keywords = $('title').html()
console.log(keywords)
Results:
Edit Conference
undefined
Test #4
Coffeescript
$ ->
keywords = $('#conference_state_id').html()
console.log(keywords)
Generated jQuery
(function() {
$(function() {
var keywords;
keywords = $('#conference_state_id').html();
return console.log(keywords);
});
}).call(this);
Output:
nothing output
Test #5
Coffeescript
keywords = $('#conference_state_id').html()
console.log(keywords)
Generated jQuery
(function() {
var keywords;
keywords = $('#conference_state_id').html();
console.log(keywords);
}).call(this);
Output:
undefined
Test #6
In the Console
keywords = $('#conference_state_id').html()
console.log(keywords)
Results
<option value=""></option>
<option value="1">Alabama</option>
<option value="2">Alaska</option>
<option value="3">Arizona</option>
<option value="4">Arkansas</option>
...
<option value="56">Northern Mariana Islands</option>
undefined
If there is anything else, please let me know.
UPDATE
I may have determined what the issue is, but still unsure how to fix it. I have JQuery loading in my application.js and my active_admin.js
// application.js manifest
//
//= require jquery
//= require jquery_ujs
//= require bootstrap
//= require user
//= require jquery_nested_form
//= require_tree .
// active_admin.js manifest
//
//= require jquery
//= require jquery_ujs
//= require jquery.ui.core
//= require jquery.ui.widget
//= require jquery.ui.datepicker
//= require active_admin/application
Page Source Code
<script src="/assets/application.js" type="text/javascript"></script>
<script src="/assets/active_admin.js" type="text/javascript"></script>
Each one is loading "jQuery JavaScript Library v1.10.0". I also have this error occuring which led me to believe that I have the 2 JQuery issue.
Uncaught TypeError: Object [object Object] has no method 'tooltip'
Thanks!