Part of my application counts the number of times a link was clicked.
The Link.click function should increment the @link.clicks attribute.
@link = Link.find(params[:id])
flash[:error] = ‘Could not update clicks’
redirect_to :action => ‘list’
would do the trick. But I can’t get @link.increment to work. Instead
if @link.update_attribute('clicks', @link.clicks+1)
does the trick, but it’s a cludge.
I’m just learning Ruby and I’m still wrapping my head around the proper
use of attributes. I’m sure I’m making some stupid mistake with the
@link.increment line. If someone could point it out, I’d be grateful.