Skip to content

Instantly share code, notes, and snippets.

View adelevie's full-sized avatar

Alan deLevie adelevie

View GitHub Profile
puts "hello"
the error is tripped by this:
purchase = Purchase.all(:id => params[:id])
the error:
C:\Users\adelevie\ruby_apps\expenser>ruby main.rb
== Sinatra/0.9.4 has taken the stage on 4567 for development with backup from Mo
ngrel
NoMethodError: undefined method `bytesize' for #<Purchase:0x5a57738>
C:/Ruby/lib/ruby/gems/1.8/gems/sinatra-0.9.4/lib/sinatra/base.rb:46:in `
finish'
require 'sinatra'
require 'activerecord'
#db settings
ActiveRecord::Base.establish_connection(
:adapter => '',
:encoding => '',
:database => '',
:username => '',
:password => '',
user = User.find(:all, :conditions => "users.name = 'Alan'")[0]
User.attribute_names.each {|attribute| user.method(attribute).call}
<% form_for @search do |f| %>
<p>
<%= f.label :starttime %>
<br />
After: <%= f.datetime_select :created_on_gte, :size => 12 %>
<br />
Before: <%= f.datetime_select :created_on_lte, :size => 12 %>
</p>
<input type='submit' value='search' />
<% end %>
module ApplicationHelper
#...
def feature(name)
if Feature.exists?(:name => name)
Feature.find_by_name(name).deployed?
else
Feature.create(:name => name, :deployed => false)
false
end
end
#read more about abingo here: http://www.bingocardcreator.com/abingo/
def self.find_alternative_for_user(test_name, alternatives)
alternatives_array = retrieve_alternatives(test_name, alternatives)
alternatives_array[self.modulo_choice(test_name, alternatives_array.size)]
end
#Quickly determines what alternative to show a given user. Given a test name
#and their identity, we hash them together (which, for MD5, provably introduces
#enough entropy that we don't care) otherwise
require 'rools'
class User
attr_accessor :bankroll, :ready_to_quit
def initialize
@bankroll = bankroll = 1000
@ready_to_quit = ready_to_quit = false
end
>> foo.later_date = 1000.days + foo.created_at
TypeError: ActiveSupport::TimeWithZone can't be coerced into Fixnum
from /home/adelevie/ruby/gems/gems/activesupport-2.3.5/lib/active_support/time_with_zone.rb:309:in `+'
from /home/adelevie/ruby/gems/gems/activesupport-2.3.5/lib/active_support/duration.rb:22:in `+'
from (irb):8
>> foo.later_date = foo.created_at + 1000.days
=> Mon, 09 Aug 2010 18:37:04 EDT -04:00
#app/models/post.rb
class Post < ActiveRecord::Base
serialize :meta_data
end
#some_controller.rb
post = Post.find(params[:id])
post.meta_data = User.find_by_name(params[:user][:name])
post.save