Jquery - word is not defined

Just starting out with a beginner book on jquery and the very first
thing I am trying fails (has to be me)

Rails 3.1 - other jquery things working including a poor example of drag
& drop that is my ultimate target here but just simply trying to get
every alternating row in a table to have a different css class

So I’m using…

app/assets/javascripts/people.js.coffee and put in…

$(document).ready(function() {
$(‘tr:nth-child(odd)’).addClass(‘odd’);
});

and I get the error -
word is not defined
(in
/home/users/cwhite/tti_framework/app/assets/javascripts/people.js.coffee)

So I tried variations including
$(document).ready(function() {
$(‘tr:odd’).addClass(‘odd’);
});

but still the same problem and my css does indeed have tr.odd defined
and works fine if I do odd_even in the view code which I removed for the
benefit of this test.


Craig W. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[email protected]
1.800.869.6908 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Need help communicating between generations at work to achieve your
desired success? Let us help!

On Dec 5, 2011, at 4:55 PM, Craig W. wrote:

$(‘tr:nth-child(odd)’).addClass(‘odd’);

What happens when you just run $(‘tr:nth-child(odd)’).addClass(‘odd’);
on the web console? Does it correctly select the elements you are
looking for ?

and I get the error -
word is not defined
(in /home/users/cwhite/tti_framework/app/assets/javascripts/people.js.coffee)

“word is not defined” is a little vague, do you think that’s happening
in jQuery, coffeescript, or your code? (these are rhetorical questions
to point you in the right direction). Also, is that a Rails exception
(I’d assume not) or a Javascript error you see in the console (or an
error during coffeescript’s compile?)

but still the same problem and my css does indeed have tr.odd defined and works
fine if I do odd_even in the view code which I removed for the benefit of this
test.

So… it’s a little hard to follow you’re debugging steps, are you
saying that the code you are executing is actually working to add the
class to the selected elements?

If that’s the case, remove your code altogether and see if the problems
is still happening. If it is, you have a different problem unrelated to
the $(‘tr:nth-child(odd)’) selector

On Dec 5, 2011, at 5:04 PM, Jason Fleetwood-Boldt wrote:

So… it’s a little hard to follow you’re debugging steps, are you saying that
the code you are executing is actually working to add the class to the selected
elements?

Grammatical correction: “your debugging steps”

You may not have property path to jquery/ .js file. Get Firebug in
firefox,
to remove the error.

On Mon, Dec 5, 2011 at 2:08 PM, Jason Fleetwood-Boldt

On Dec 5, 2011, at 3:04 PM, Jason Fleetwood-Boldt wrote:

On Dec 5, 2011, at 4:55 PM, Craig W. wrote:

$(‘tr:nth-child(odd)’).addClass(‘odd’);

What happens when you just run $(‘tr:nth-child(odd)’).addClass(‘odd’); on the
web console? Does it correctly select the elements you are looking for ?


commenting out the relevant lines in people.js.coffee and then opening
up the console in FF and executing returns…

Error: $ is not defined
Source File: javascript:%20$(‘tr:nth-child(odd)’).addClass(‘odd’);
Line: 1

and I get the error -
word is not defined
(in /home/users/cwhite/tti_framework/app/assets/javascripts/people.js.coffee)

“word is not defined” is a little vague, do you think that’s happening in
jQuery, coffeescript, or your code? (these are rhetorical questions to point you
in the right direction). Also, is that a Rails exception (I’d assume not) or a
Javascript error you see in the console (or an error during coffeescript’s
compile?)


ExecJS::ProgramError in People#index

Showing
/home/users/cwhite/tti_framework/app/views/layouts/fluid.html.erb where
line #7 raised:

word is not defined
(in
/home/users/cwhite/tti_framework/app/assets/javascripts/people.js.coffee)

Extracted source (around line #7):

4: TtiFramework
5:
6: <%= stylesheet_link_tag “application” %>
7: <%= javascript_include_tag “application” %>
8:
9:
10: <%= csrf_meta_tags %>

Rails.root: /home/users/cwhite/tti_framework
Application Trace | Framework Trace | Full Trace

app/views/layouts/fluid.html.erb:7:in
_app_views_layouts_fluid_html_erb___36715814_94758920' app/controllers/people_controller.rb:16:inindex’

I am omitting the stack trace purposely

but still the same problem and my css does indeed have tr.odd defined and works
fine if I do odd_even in the view code which I removed for the benefit of this
test.

So… it’s a little hard to follow you’re debugging steps, are you saying that
the code you are executing is actually working to add the class to the selected
elements?

If that’s the case, remove your code altogether and see if the problems is still
happening. If it is, you have a different problem unrelated to the
$(‘tr:nth-child(odd)’) selector


No - I wasn’t saying that.

This was my view code (which works) prior to my attempts to use jquery’s
alternating table row scheme…
<%
odd_or_even = 0
for person in @people
odd_or_even = 1 - odd_or_even
%>



<%= link_to person.uid, :action => ‘show’, :id => person.id
%>
… <% end %>

and this is what it looks like when trying to use jquery’s alternating
table scheme…
<% for person in @people %>



<%= link_to person.uid, :action => ‘show’, :id => person.id
%>
… <% end %>

Craig

(these are just a lot of suggestions… take it with a grain of salt)

Right… so for some reason jQuery isn’t included properly (I know that
from “Error: $ is not defined”)… although I’m not sure how you are
even able to get that far given the other error you said you had.

It’s interesting that javascript_include_tag (line 7) is throwing the
exception “word is not defined”

Looks like that problem is in the ExecJS Gem – is that default in Rails
3.1? Did you add that? Remove that Gem from your Gemfile, rebuild the
gems (bundle install) and see if the problem goes away.

I guess that Gem is part of Rail’s default package now? (That is,
automatically included in the Gemfile when you make a new app)

Not actually sure what your problem is but it looks like that Gem is
aliasing the javascript_include_tag which is making it not too happy.

Maybe try examining the line of code in execjs that it is hiccuping on
(You should be able to find that from your stacktrace)? Perhaps that
will have clues as to why it is hiccuping when trying to execute
javascript_include_tag

well I’m reasonably certain that the problem is getting the base
jquery.js loaded but:

  • I am using Rails 3.1 (development mode)
  • my ‘Gemfile’ looks like this (the top part anyway)
    source ‘http://rubygems.org

gem ‘rails’, ‘3.1.3’

Bundle edge Rails instead:

gem ‘rails’, :git => ‘git://github.com/rails/rails.git’

Rails standard install gems

gem ‘pg’
gem ‘json’

gem ‘execjs’
gem ‘therubyracer’

Gems used only for assets and not required

in production environments by default.

group :assets do
gem ‘sass-rails’, ‘~> 3.1.4’
gem ‘coffee-rails’, ‘~> 3.1.1’
gem ‘uglifier’, ‘>= 1.0.3’
end

gem ‘jquery-rails’

and other jquery things are clearly working for me as I’ve gotten
rounded corners & drag/drop working (ui plugin items I think)

But I definitely don’t understand what you mean by 'you may not have
property path to jquery/ .js file. and I do have Firebug installed here.

Craig

On Dec 5, 2011, at 3:18 PM, jay parteek wrote:


You received this message because you are subscribed to the Google G. “Ruby
on Rails: Talk” group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.


Craig W. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[email protected]
1.800.869.6908 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
www.ttiassessments.com

Need help communicating between generations at work to achieve your
desired success? Let us help!

On Dec 5, 9:55pm, Craig W. [email protected] wrote:

});

A .coffees file should contain coffeescript, whereas you appear to
have put javascript in your people.js.coffee

Fred

On Dec 5, 2011, at 3:34 PM, Jason Fleetwood-Boldt wrote:

(these are just a lot of suggestions… take it with a grain of salt)

Right… so for some reason jQuery isn’t included properly (I know that from
“Error: $ is not defined”)… although I’m not sure how you are even able to get
that far given the other error you said you had.

It’s interesting that javascript_include_tag (line 7) is throwing the exception
“word is not defined”

Looks like that problem is in the ExecJS Gem – is that default in Rails 3.1?
Did you add that? Remove that Gem from your Gemfile, rebuild the gems (bundle
install) and see if the problem goes away.


Thanks for the potshots…

I suspect that wouldn’t matter since the gem would be sucked back in by
other requirements…

gem uninstall execjs

You have requested to uninstall the gem:
execjs-1.2.9
coffee-script-2.2.0 depends on [execjs (>= 0)]
sprockets-2.0.3 depends on [execjs (~> 1.0)]
uglifier-1.1.0 depends on [execjs (>= 0.3.0)]
If you remove this gems, one or more dependencies will not be met.
Continue with Uninstall? [Yn] n
ERROR: While executing gem … (Gem::DependencyRemovalException)
Uninstallation aborted due to dependent gem(s)

I guess that Gem is part of Rail’s default package now? (That is, automatically
included in the Gemfile when you make a new app)


not sure - various resources told me that I needed to include it in the
Gemfile (execjs) so I did but any bundle exec run would have put it in
there if it wasn’t so it seems moot

Not actually sure what your problem is but it looks like that Gem is aliasing
the javascript_include_tag which is making it not too happy.

Maybe try examining the line of code in execjs that it is hiccuping on (You
should be able to find that from your stacktrace)? Perhaps that will have clues as
to why it is hiccuping when trying to execute javascript_include_tag


the stacktrace and the lines in ruby_racer_runtime.rb mean nothing to me
except that it feels there is a syntax error.

execjs (1.2.9) lib/execjs/ruby_racer_runtime.rb:47:in call' execjs (1.2.9) lib/execjs/ruby_racer_runtime.rb:78:inlock’
therubyracer (0.9.9) lib/v8/c/locker.rb:13:in Locker' execjs (1.2.9) lib/execjs/ruby_racer_runtime.rb:76:inlock’
execjs (1.2.9) lib/execjs/ruby_racer_runtime.rb:40:in call' coffee-script (2.2.0) lib/coffee_script.rb:57:incompile’
tilt (1.3.3) lib/tilt/coffee.rb:46:in evaluate' tilt (1.3.3) lib/tilt/template.rb:76:inrender’
sprockets (2.0.3) lib/sprockets/context.rb:175:in evaluate' sprockets (2.0.3) lib/sprockets/context.rb:172:ineach’
sprockets (2.0.3) lib/sprockets/context.rb:172:in evaluate' sprockets (2.0.3) lib/sprockets/bundled_asset.rb:171:inbuild_dependency_context_and_body’
sprockets (2.0.3) lib/sprockets/bundled_asset.rb:135:in
dependency_context' sprockets (2.0.3) lib/sprockets/bundled_asset.rb:194:inbuild_dependencies_paths_and_assets’
sprockets (2.0.3) lib/sprockets/bundled_asset.rb:141:in
dependency_paths' sprockets (2.0.3) lib/sprockets/bundled_asset.rb:61:inmtime’
sprockets (2.0.3) lib/sprockets/asset.rb:58:in send' sprockets (2.0.3) lib/sprockets/asset.rb:58:inencode_with’
sprockets (2.0.3) lib/sprockets/asset.rb:57:in each' sprockets (2.0.3) lib/sprockets/asset.rb:57:inencode_with’
sprockets (2.0.3) lib/sprockets/bundled_asset.rb:43:in encode_with' sprockets (2.0.3) lib/sprockets/caching.rb:52:incache_asset’
sprockets (2.0.3) lib/sprockets/environment.rb:82:in build_asset' sprockets (2.0.3) lib/sprockets/base.rb:99:infind_asset’
sprockets (2.0.3) lib/sprockets/environment.rb:72:in find_asset' sprockets (2.0.3) lib/sprockets/base.rb:110:in[]’
sprockets (2.0.3) lib/sprockets/bundled_asset.rb:200:in
build_dependencies_paths_and_assets' sprockets (2.0.3) lib/sprockets/bundled_asset.rb:194:ineach’
sprockets (2.0.3) lib/sprockets/bundled_asset.rb:194:in
build_dependencies_paths_and_assets' sprockets (2.0.3) lib/sprockets/bundled_asset.rb:141:independency_paths’
sprockets (2.0.3) lib/sprockets/bundled_asset.rb:61:in mtime' sprockets (2.0.3) lib/sprockets/asset.rb:58:insend’
sprockets (2.0.3) lib/sprockets/asset.rb:58:in encode_with' sprockets (2.0.3) lib/sprockets/asset.rb:57:ineach’
sprockets (2.0.3) lib/sprockets/asset.rb:57:in encode_with' sprockets (2.0.3) lib/sprockets/bundled_asset.rb:43:inencode_with’
sprockets (2.0.3) lib/sprockets/caching.rb:52:in cache_asset' sprockets (2.0.3) lib/sprockets/environment.rb:82:inbuild_asset’
sprockets (2.0.3) lib/sprockets/trail.rb:102:in find_asset_in_path' sprockets (2.0.3) lib/sprockets/base.rb:101:infind_asset’
sprockets (2.0.3) lib/sprockets/environment.rb:72:in find_asset' sprockets (2.0.3) lib/sprockets/base.rb:110:in[]’
actionpack (3.1.3) lib/sprockets/helpers/rails_helper.rb:130:in
asset_for' actionpack (3.1.3) lib/sprockets/helpers/rails_helper.rb:27:injavascript_include_tag’
actionpack (3.1.3) lib/sprockets/helpers/rails_helper.rb:26:in collect' actionpack (3.1.3) lib/sprockets/helpers/rails_helper.rb:26:injavascript_include_tag’
actionpack (3.1.3) lib/action_view/template.rb:171:in send' actionpack (3.1.3) lib/action_view/template.rb:171:inrender’
activesupport (3.1.3) lib/active_support/notifications.rb:55:in
instrument' actionpack (3.1.3) lib/action_view/template.rb:169:inrender’
actionpack (3.1.3) lib/action_view/renderer/template_renderer.rb:52:in
render_with_layout' actionpack (3.1.3) lib/action_view/renderer/template_renderer.rb:38:inrender_template’
actionpack (3.1.3) lib/action_view/renderer/template_renderer.rb:12:in
render' actionpack (3.1.3) lib/action_view/renderer/abstract_renderer.rb:22:inwrap_formats’
actionpack (3.1.3) lib/action_view/renderer/template_renderer.rb:9:in
render' actionpack (3.1.3) lib/action_view/renderer/renderer.rb:36:inrender_template’
actionpack (3.1.3) lib/action_view/renderer/renderer.rb:17:in render' actionpack (3.1.3) lib/abstract_controller/rendering.rb:120:in_render_template’
actionpack (3.1.3) lib/action_controller/metal/streaming.rb:250:in
_render_template' actionpack (3.1.3) lib/abstract_controller/rendering.rb:114:inrender_to_body’
actionpack (3.1.3) lib/action_controller/metal/renderers.rb:30:in
render_to_body' actionpack (3.1.3) lib/action_controller/metal/compatibility.rb:43:inrender_to_body’
actionpack (3.1.3) lib/abstract_controller/rendering.rb:99:in render' actionpack (3.1.3) lib/action_controller/metal/rendering.rb:16:inrender’
actionpack (3.1.3) lib/action_controller/metal/instrumentation.rb:40:in
render' activesupport (3.1.3) lib/active_support/core_ext/benchmark.rb:5:inms’
/usr/local/lib/ruby/1.8/benchmark.rb:308:in realtime' activesupport (3.1.3) lib/active_support/core_ext/benchmark.rb:5:inms’
actionpack (3.1.3) lib/action_controller/metal/instrumentation.rb:40:in
render' actionpack (3.1.3) lib/action_controller/metal/instrumentation.rb:78:incleanup_view_runtime’
activerecord (3.1.3)
lib/active_record/railties/controller_runtime.rb:24:in
cleanup_view_runtime' activeldap (3.1.1) lib/active_ldap/railties/controller_runtime.rb:24:incleanup_view_runtime’
actionpack (3.1.3) lib/action_controller/metal/instrumentation.rb:39:in
render' actionpack (3.1.3) lib/action_controller/metal/implicit_render.rb:10:indefault_render’
actionpack (3.1.3) lib/action_controller/metal/mime_responds.rb:268:in
retrieve_response_from_mimes' actionpack (3.1.3) lib/action_controller/metal/mime_responds.rb:195:incall’
actionpack (3.1.3) lib/action_controller/metal/mime_responds.rb:195:in
respond_to' actionpack (3.1.3) lib/action_controller/metal/implicit_render.rb:4:insend_action’
actionpack (3.1.3) lib/action_controller/metal/implicit_render.rb:4:in
send_action' actionpack (3.1.3) lib/abstract_controller/base.rb:167:inprocess_action’
actionpack (3.1.3) lib/action_controller/metal/rendering.rb:10:in
process_action' actionpack (3.1.3) lib/abstract_controller/callbacks.rb:18:inprocess_action’
activesupport (3.1.3) lib/active_support/callbacks.rb:425:in
_run__29468547__process_action__199225275__callbacks' activesupport (3.1.3) lib/active_support/callbacks.rb:386:insend’
activesupport (3.1.3) lib/active_support/callbacks.rb:386:in
_run_process_action_callbacks' activesupport (3.1.3) lib/active_support/callbacks.rb:81:insend’
activesupport (3.1.3) lib/active_support/callbacks.rb:81:in
run_callbacks' actionpack (3.1.3) lib/abstract_controller/callbacks.rb:17:inprocess_action’
actionpack (3.1.3) lib/action_controller/metal/rescue.rb:17:in
process_action' actionpack (3.1.3) lib/action_controller/metal/instrumentation.rb:30:inprocess_action’
activesupport (3.1.3) lib/active_support/notifications.rb:53:in
instrument' activesupport (3.1.3) lib/active_support/notifications/instrumenter.rb:21:ininstrument’
activesupport (3.1.3) lib/active_support/notifications.rb:53:in
instrument' actionpack (3.1.3) lib/action_controller/metal/instrumentation.rb:29:inprocess_action’
actionpack (3.1.3) lib/action_controller/metal/params_wrapper.rb:201:in
process_action' activerecord (3.1.3) lib/active_record/railties/controller_runtime.rb:18:inprocess_action’
activeldap (3.1.1) lib/active_ldap/railties/controller_runtime.rb:18:in
process_action' actionpack (3.1.3) lib/abstract_controller/base.rb:121:inprocess’
actionpack (3.1.3) lib/abstract_controller/rendering.rb:45:in process' actionpack (3.1.3) lib/action_controller/metal.rb:193:indispatch’
actionpack (3.1.3) lib/action_controller/metal/rack_delegation.rb:14:in
dispatch' actionpack (3.1.3) lib/action_controller/metal.rb:236:inaction’
actionpack (3.1.3) lib/action_dispatch/routing/route_set.rb:65:in call' actionpack (3.1.3) lib/action_dispatch/routing/route_set.rb:65:indispatch’
actionpack (3.1.3) lib/action_dispatch/routing/route_set.rb:29:in call' rack-mount (0.8.3) lib/rack/mount/route_set.rb:152:incall’
rack-mount (0.8.3) lib/rack/mount/code_generation.rb:96:in recognize' rack-mount (0.8.3) lib/rack/mount/code_generation.rb:75:inoptimized_each’
rack-mount (0.8.3) lib/rack/mount/code_generation.rb:95:in recognize' rack-mount (0.8.3) lib/rack/mount/route_set.rb:141:incall’
actionpack (3.1.3) lib/action_dispatch/routing/route_set.rb:532:in
call' actionpack (3.1.3) lib/action_dispatch/middleware/best_standards_support.rb:17:incall’
rack (1.3.5) lib/rack/etag.rb:23:in call' rack (1.3.5) lib/rack/conditionalget.rb:25:incall’
actionpack (3.1.3) lib/action_dispatch/middleware/head.rb:14:in call' actionpack (3.1.3) lib/action_dispatch/middleware/params_parser.rb:21:incall’
actionpack (3.1.3) lib/action_dispatch/middleware/flash.rb:247:in call' rack (1.3.5) lib/rack/session/abstract/id.rb:195:incontext’
rack (1.3.5) lib/rack/session/abstract/id.rb:190:in call' actionpack (3.1.3) lib/action_dispatch/middleware/cookies.rb:331:incall’
activerecord (3.1.3) lib/active_record/query_cache.rb:64:in call' activerecord (3.1.3) lib/active_record/connection_adapters/abstract/connection_pool.rb:477:incall’
actionpack (3.1.3) lib/action_dispatch/middleware/callbacks.rb:29:in
call' activesupport (3.1.3) lib/active_support/callbacks.rb:392:in_run_call_callbacks’
activesupport (3.1.3) lib/active_support/callbacks.rb:81:in send' activesupport (3.1.3) lib/active_support/callbacks.rb:81:inrun_callbacks’
actionpack (3.1.3) lib/action_dispatch/middleware/callbacks.rb:28:in
call' actionpack (3.1.3) lib/action_dispatch/middleware/reloader.rb:68:incall’
rack (1.3.5) lib/rack/sendfile.rb:101:in call' actionpack (3.1.3) lib/action_dispatch/middleware/remote_ip.rb:48:incall’
actionpack (3.1.3)
lib/action_dispatch/middleware/show_exceptions.rb:47:in call' railties (3.1.3) lib/rails/rack/logger.rb:13:incall’
rack (1.3.5) lib/rack/methodoverride.rb:24:in call' rack (1.3.5) lib/rack/runtime.rb:17:incall’
activesupport (3.1.3)
lib/active_support/cache/strategy/local_cache.rb:72:in call' rack (1.3.5) lib/rack/lock.rb:15:incall’
actionpack (3.1.3) lib/action_dispatch/middleware/static.rb:53:in call' railties (3.1.3) lib/rails/engine.rb:456:incall’
rack (1.3.5) lib/rack/content_length.rb:14:in call' railties (3.1.3) lib/rails/rack/log_tailer.rb:14:incall’
rack (1.3.5) lib/rack/handler/webrick.rb:59:in service' /usr/local/lib/ruby/1.8/webrick/httpserver.rb:104:inservice’
/usr/local/lib/ruby/1.8/webrick/httpserver.rb:65:in run' /usr/local/lib/ruby/1.8/webrick/server.rb:173:instart_thread’
/usr/local/lib/ruby/1.8/webrick/server.rb:162:in start' /usr/local/lib/ruby/1.8/webrick/server.rb:162:instart_thread’
/usr/local/lib/ruby/1.8/webrick/server.rb:95:in start' /usr/local/lib/ruby/1.8/webrick/server.rb:92:ineach’
/usr/local/lib/ruby/1.8/webrick/server.rb:92:in start' /usr/local/lib/ruby/1.8/webrick/server.rb:23:instart’
/usr/local/lib/ruby/1.8/webrick/server.rb:82:in start' rack (1.3.5) lib/rack/handler/webrick.rb:13:inrun’
rack (1.3.5) lib/rack/server.rb:265:in start' railties (3.1.3) lib/rails/commands/server.rb:70:instart’
railties (3.1.3) lib/rails/commands.rb:54
railties (3.1.3) lib/rails/commands.rb:49:in tap' railties (3.1.3) lib/rails/commands.rb:49 script/rails:6:inrequire’
script/rails:6

$(‘tr:nth-child(odd)’).addClass(‘odd’);

7: <%= javascript_include_tag “application” %>
I am omitting the stack trace purposely

  <td><%= link_to person.uid, :action => 'show', :id => person.id %></td>

To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.


Craig W. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[email protected]
1.800.869.6908 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
www.ttiassessments.com

Need help communicating between generations at work to achieve your
desired success? Let us help!

On Dec 6, 2011, at 12:29 AM, Frederick C. wrote:

$(document).ready(function() {
$(‘tr:nth-child(odd)’).addClass(‘odd’);

});

A .coffees file should contain coffeescript, whereas you appear to
have put javascript in your people.js.coffee


::::blush::::

told you I was just starting out and it had to be me - just had to be in
the most basic way imaginable.

That was it - thanks as always.

Craig

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs