Skip to content

Instantly share code, notes, and snippets.

#Should this not cause my record to be deleted after I update it? Doesn't seem to work for me..
class Timer < ActiveRecord::Base
after_save :destroy_timer
private
def destroy_timer
self.destroy
end
end
#timers_helper.rb
module TimersHelper
def seconds_left
[(@timer.target - Time.now).round, 0].max
end
end
#timers_controller.rb
def refresh
#relevant controller
def show
@timer = Timer.find(params[:id])
respond_to do |format|
format.html
format.js { render layout: false }
end
end
source 'http://rubygems.org'
gem 'rails', '3.1.1'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'sqlite3'
gem 'mysql2'
#Trying to have my root behave like my timers controller,
#so I wouldn't have to prefix everything with 'timers/' in the URLs
#resources :timers
root to: "timers#index", as: :timers
match '/:id' => 'timers#show', as: :timer
match '/new' => 'timers#new', as: :new_timer
# When I do this:
animation = {
amount: 20,
ready: true,
anim: function(dir, el) {
amount = dir * this.amount;
if (this.ready) {
this.ready = false;
el.animate({
left: '+=' + amount,
top: '+=' + amount
over = {
amount: 20,
ready: true,
anim: function(dir, el) {
amount = dir * this.amount;
if (this.ready) {
this.ready = false;
el.animate({
left: '+=' + amount,
top: '+=' + amount