• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

CoffeeScript code only works sometimes

 
village idiot
Posts: 1208
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've got this in a js.coffee file in my tutorial web app:


This makes a particular post, called a status, change color and display links to edit or delete the post. It only works when the page is first loaded into the browser as the index page, or when redirected to as root_url by the sign_out action. When the same page is loaded by clicking on a link using statuses_path, nothing happens when you mouse over the statuses. It's the same page, with the same url, but the script doesn't work after clicking one of the links. If I reload the page, or sign in and then sign out, the script works.

I didn't notice this problem until I decided to scratch devise and do the authentication from scratch, so I could add custom fields to the form that actually worked. I got the authentication working okay, but I can't figure out what is going on with this script. It seems to me that the same page should work the same, regardless of how you got there, but obviously I'm missing something here.

What can I do to correct this?
 
Carol Murphy
village idiot
Posts: 1208
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay, so I tried comparing the pages that were generated, and the html was identical. However, when I inspected the status element on each page, .status.hover
was being applied on the working page, but not on the broken page.
Could this be a CSS incompatibility somewhere? I have a custom.css.scss file that imports a bootstrap gem, the application.css and statuses.css.scss. Where should I look to figure this annoying little mystery out?

What would cause the coffeescript to stop responding to a hover when the page is accessed via statuses_path, but work okay via root_url?
 
Carol Murphy
village idiot
Posts: 1208
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Eureka! This is a known issue with turbolinks! Thank you Stack Overflow! The problem occurs because the page is not reloaded when the links are clicked, so the script is not called. To solve this, I installed the jquery-turbolinks gem and required it right after jquery in the application.js file. Now the hover effect works after clicking on a link, too.
I don't know why posting my questions here help me to solve my problems, but it does, even when I'm the only person responding to my posts. OMG......I'm talking to myself more and more....and now I'm responding to myself as well.
Oh well, it seems to be working for me!
 
reply
    Bookmark Topic Watch Topic
  • New Topic