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...
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.
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
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'
# 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.
(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
(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.
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...
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...