Helpers -n- Comments

19 Mar

It took some hair-pulling (okay, a LOT of hair-pulling) but I finally got comments working on the Target Cancer site. Happiness! There’s still no user authentication, so anyone can post a comment (please bear in mind the site is actually being used already if you do any poking around – which is welcome) without having to log in or anything sensible and secure like that, but…IT WORKS!

I tried to do it all by hand at first and ran into trouble, then tore it down and did it again using scaffolding to give me a head start. Still ran into trouble, but this time I eventually got past it!

Not sure I can make sense quite yet of what the trouble was, as I am still rather at the ‘flailing’ stage as a developer when things go awry. Story of my life, really. I am getting better, though, at finding the trouble spots that matter. I remember the utter cluelessness I felt when first trying to get a grip on rails basics and, well, I’m beyond that at least!

I also wrote a very simple helper method:

module ApplicationHelper

  def commentsCount(song_id)
    count = Comment.where(song_id: song_id).size


Hey, I told you it was simple didn’t I? I use it to get a count of the comments for a particular song so that the comments link can have the current number of comments for that song in parens next to it. Works great!


Comments are welcome!

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: