Skip to content

Instantly share code, notes, and snippets.

@repertoire
repertoire / gist:1058421
Created July 1, 2011 12:11
WTF is going on with named resource routes
$ be rake routes | grep document
/opt/local/lib/ruby1.9/gems/1.9.1/gems/rake-0.9.2/lib/rake/file_utils.rb:10: warning: already initialized constant RUBY
/opt/local/lib/ruby1.9/gems/1.9.1/gems/rake-0.9.2/lib/rake/file_utils.rb:84: warning: already initialized constant LN_SUPPORTED
documents GET /documents(.:format) {:action=>"index", :controller=>"documents"}
POST /documents(.:format) {:action=>"create", :controller=>"documents"}
new_document GET /documents/new(.:format) {:action=>"new", :controller=>"documents"}
edit_document GET /documents/:id/edit(.:format) {:action=>"edit", :controller=>"documents"}
document GET /documents/:id(.:format) {:action=>"show", :controller=>"documents"}
PUT /documents/:id(.:format) {:action=>"update", :controller=>"documents"}
DELETE /documents/:id(.:format) {:action=>"destroy", :controller=>"documents"}
@repertoire
repertoire / gist:1035618
Created June 20, 2011 13:43
proper way to do this?
class MyModel < ActiveRecord::Base
attr_accessible :some_string
acts_as_somethinger :some_string
end
> a_my_model = MyModel.new
> a_my_model.some_string = 'This is a string.'
> a_my_model.some_string.do_something
"something!"
>
class Video < ActiveRecord::Base
has_many :video_locations
has_many :locations, :through => :video_locations
accepts_nested_attributes_for :locations
has_many :video_people
has_many :people, :through => :video_people
attr_accessible :title, :date, :url
validates_presence_of :title, :date, :url
class Video < ActiveRecord::Base
has_many :video_locations
has_many :locations, :through => :video_locations
accepts_nested_attributes_for :locations
def locations_attributes=(attributes)
logger.debug "IS THIS EVEN GETTING CALLED!?!??!? Attributes: #{attributes.inspect}"
attributes.each do |attr|
locations.new(:lat => attr.lat, :lng => attr.lng)
end
class Video < ActiveRecord::Base
has_many :video_locations
has_many :locations, :through => :video_locations
attr_accessible :title, :date, :url
validate :validates_presence_of_locations
def validates_presence_of_locations
errors.add(:locations, "must have at least one video") if
locations.length < 1
@repertoire
repertoire / gist:750091
Created December 21, 2010 15:50
Bundle/gem problems
Fetching source index for http://rubygems.org/
Bundler could not find compatible versions for gem "pg":
In Gemfile:
repertoire-faceting (~> 0.5.3) depends on
pg (~> 0.9.0)
activerecord-postgis-adapter depends on
pg (0.10.0)