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:in
index’
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