This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
puts "hello" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'sinatra' | |
require 'activerecord' | |
#db settings | |
ActiveRecord::Base.establish_connection( | |
:adapter => '', | |
:encoding => '', | |
:database => '', | |
:username => '', | |
:password => '', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
user = User.find(:all, :conditions => "users.name = 'Alan'")[0] | |
User.attribute_names.each {|attribute| user.method(attribute).call} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<% 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 %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rools' | |
class User | |
attr_accessor :bankroll, :ready_to_quit | |
def initialize | |
@bankroll = bankroll = 1000 | |
@ready_to_quit = ready_to_quit = false | |
end | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>> 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 |
OlderNewer