Skip to content

Instantly share code, notes, and snippets.

@sirramongabriel
sirramongabriel / gist:3919201
Created October 19, 2012 16:32
Vote counter code...
# post_controller.rb
class PostsController < ApplicationController
def index
@posts = Post.find(:all)
end
def new
@post = Post.new
end
@sirramongabriel
sirramongabriel / gist:3919463
Created October 19, 2012 17:24
vote count: replacing boolean values with strings in post.rb and the server output.
Hear is the server output. I explicitly hit the upvote link for demo purposes. This is also the server output with the suggested edit of replacing boolean values with strings in my post.rb model for the method vote_total. As far as I can understand, no matter which link I select (up or down vote), the value starts properly but gets submitted as 0.
Here is my updated Post.rb model containing the vote_total method.
class Post < ActiveRecord::Base
attr_accessible :URL, :description, :is_link
has_many :comments, dependent: :destroy
has_many :votes, dependent: :destroy
@sirramongabriel
sirramongabriel / gist:4366840
Last active December 10, 2015 02:19
A list of code snippets for my 324 SO question asked on 12-23-12
# controllers/assessment_plan_form_controller.rb
class AssessmentPlanFormsController < ApplicationController
before_filter :get_resident
def index
@assessment_plan_forms = @resident.assessment_plan_forms
end
def new
<%= f.date_select(:form_date, order: [:month, :day, :year], prompt: { month: 'Select Month', day: 'Select Day', year: 'Select Year' }, start_year: 2000, size: 1)
@sirramongabriel
sirramongabriel / NoMethodError
Created July 7, 2013 21:49
server output shows NoMethodError for created_at
Started GET "/residents/1" for 127.0.0.1 at 2013-07-07 17:47:03 -0400
Processing by ResidentsController#show as HTML
Parameters: {"authenticity_token"=>"TkgTe0hwIOCaHtU6UxXrh6QVOd4YDoK26svqX/lJVfk=", "id"=>"1"}
Admin Load (0.4ms) SELECT "admins".* FROM "admins" WHERE "admins"."id" = 1 LIMIT 1
Resident Load (1.6ms) SELECT "residents".* FROM "residents"
Resident Load (1.2ms) SELECT "residents".* FROM "residents" WHERE "residents"."id" = ? LIMIT 1 [["id", "1"]]
AssessmentPlanForm Load (1.0ms) SELECT "assessment_plan_forms".* FROM "assessment_plan_forms"
AssessmentPlanForm Load (1.0ms) SELECT "assessment_plan_forms".* FROM "assessment_plan_forms" WHERE "assessment_plan_forms"."resident_id" = 1 AND "assessment_plan_forms"."id" = ? LIMIT 1 [["id", "1"]]
Rendered chart_alerts/up_to_date/_assessment_plan_form_success_alert.html.erb (0.1ms)
MedRecordForm Load (9.7ms) SELECT "med_record_forms".* FROM "med_record_forms"
[2013-08-21 13:19:48] INFO WEBrick 1.3.1
[2013-08-21 13:19:48] INFO ruby 2.0.0 (2013-06-27) [x86_64-darwin10.8.0]
[2013-08-21 13:19:48] INFO WEBrick::HTTPServer#start: pid=11295 port=3000
Started GET "/subscriptions" for 127.0.0.1 at 2013-08-21 13:19:52 -0400
Processing by SubscriptionsController#index as HTML
Subscription Load (0.7ms) SELECT "subscriptions".* FROM "subscriptions"
Rendered subscriptions/index.html.erb within layouts/application (15.3ms)
Rendered layouts/_shim.html.erb (6.5ms)
@sirramongabriel
sirramongabriel / project_jukebox1
Last active December 22, 2015 02:58
project_jukebox1 snippet
class Song
def initialize(self, artist, title, genre)
@song = Self.new
@artist = artist
@title = title
@genre = genre
end
end
@sirramongabriel
sirramongabriel / account.rb
Last active December 22, 2015 04:28
From project banking. The account class
# account.rb
class Account
def initialize
@balance = 1000.00
end
attr_accessor :amount
def send_deposit
"#{deposit(amount, current_balance).to_f}"
@sirramongabriel
sirramongabriel / interact.rb
Last active December 22, 2015 04:28
interact.rb is a file from project banking and is intended to house communication
# interact.rb
require_relative 'account'
class Interact
def greeting
puts "Welcome to bank."
end
def farewell
puts "Have a good day, we value your money here at bank."
@sirramongabriel
sirramongabriel / banking.rb
Created September 2, 2013 20:57
banking.rb is part of the banking project
# banking.rb
require_relative 'interact'
require_relative 'account'
deposit = Account.new
withdraw = Account.new
banking = Interact.new
puts "#{banking.greeting}"