The question is at the bottom, but the code describes the bulk of it :)
Here's the base of the code, shortened to get to the core of it:
ActiveRecord::Base.class_eval do
def self.joins(*others)
has_many :parent_join_models, :as => :child
has_many :child_join_models, :as => :parent
options = others.extract_options!
th...
How do I use methods from two different namespaces?
class Bar
def self.configure &block
new.instance_eval &block
end
def method2
puts "from Bar"
end
end
class Foo
def method1
puts "from Foo"
end
def start
Bar.configure do
method1
method2
end
end
end
Foo.new.start
In the above example...
I'm running into an interesting issue with the relatively simple assignment below. Each of the parenthesized chunks in the beginning evaluate to nil, leaving Rubygame::Surface.new as the value that @image ought to be assigned to. Unfortunately on the next line where I set @rect, it throws a NoMethodError because @image is nil.
@image = ...
Hi.
I was reindexing my model when I suddenly shutdown my mac,
When I try to reindex again using (Model_name).reindex in script/console I encountered an error that I haen't encountered before.
RSolr::RequestError: Solr Response: Severe_errors_in_solr_configuration__Check_your_log_files_for_more_detailed_information_on_what_may_be_wrong...
I've been having a problem uploading a CSV file to Heroku and processing it. It works fine in my local environment. Just do be clear, I don't need to save the file on Heroku, just access it during the request in order to convert it into a string for processing and importing into the DB.
What I want to do is:
Upload CSV file
Strip out ...
>> events.first
=> #<Bandsintown::Event:0x1037caf98 @venue=#<Bandsintown::Venue:0x1037c9580 @region="Australia", @bandsintown_id="160698", @latitude="-37.8161090", @city="Melbourne Vic", @bandsintown_url="http://www.bandsintown.com/venue/160698", @longitude="144.9725040", @country="Australia", @name="Rod Laver Arena at Melbourne Park...
>> events.first.datetime
=> Wed Sep 15 19:00:00 -0400 2010
>> Time.parse(events.first.datetime)
NoMethodError: private method `gsub!' called for Wed Sep 15 19:00:00 -0400 2010:Time
...
Hi everyone,
I am trying to install rails 3.0.0. and am getting this error during install. Anyone have any clue how to work around this?
C:\Ruby187\bin>gem install rails -v 3.0.0
Successfully installed activesupport-3.0.0
Successfully installed builder-2.1.2
Successfully installed i18n-0.4.1
Successfully installed activemodel-3.0.0
Su...
I'm using Sinatra, and I wanted to set up some of the convenience rake tasks that Rails has, specifically rake db:seed.
My first pass was this:
namespace :db do
desc 'Load the seed data from db/seeds.rb'
task :seed do
seed_file = File.join(File.dirname(__FILE__), 'db', 'seeds.rb')
system("racksh < #{seed_file}")
end
end
...
How do I tell Ruby to add a path in $LOAD_PATH and require all libraries automatically every time the interpreter fires up?
That is to say, I don't want to load my libraries manually.
Eg:
cd /my_libraries
git clone <git_repo_to_thor_gem>
Then I want ruby to use that one instead of the gem I installed because I want to change the sou...
Possible Duplicate:
Meaning of ~> in version requirement
I often stumble upon the ~> operator.
eg.
gem 'httparty', '~> 0.5.2'
What does it mean?
...
Anyone that knows how to do basic_auth with rest-client?
http://github.com/archiloque/rest-client
I need to create a private repository on GitHub through their Restful API.
...
I am working on a small script using the USB bindings for ruby.
Since this is just a wrapper around libusb, all of C++'s features are visible through the abstraction, for example when usb_bulk_read requires giving a buffer as an argument (which would just be a pointer in C).
How can I create a buffer which is 64bytes long, for the foll...
I'm using Haml in rails and have been writting with the :markdown filter (bluecloth gem), but a piece of example code is in ruby and the page tries to execute the #{values}, how can I stop this?
Here is the breaking bit of code:
:markdown
like_frags = [fields].flatten.map { |f| "LOWER(#{f}) LIKE :word#{count}" }
or_frags << "(#{l...
If I have a class like the following, how do I tell when an ancestor is a class vs. a module?
ActiveRecord::Base.send(:include, SomeLibrary)
class Group < ActiveRecord::Base
include SomeLibrary::Core
end
class SubGroup < Group
end
ancestor_names = SubGroup.ancestors.map(&:name)
puts ancestor_names.inspect
#=> [
"SubGroup", "So...
How would I match 'ber' to the end so it picks up 'ber/sunday/wednesday'
monday/october/sunday/wednesday
...
I want to have an array as a instance variable using attr_accessor.
But isn't attr_accessor only for strings?
How do I use it on an array?
UPDATE:
Eg. If you want:
object.array = "cat"
object.array = "dog"
pp object.array
=> ["cat", "dog"]
Then you have to create those methods yourself?
...
I thought it was possible to define attr_accessor methods in a eigenclass like this:
class IOS
@@modules_paths = "hello"
class << self
attr_accessor :modules_paths
end
end
puts IOS::modules_paths
But this returns nothing.
Is there a way to do it?
...
Hi all:
This is just for my weekend project/study, I am very new to Sinatra and MongoDB.
I've installed the gems for mongoDB, such as: mongo, mongo_mapper and mongoid.
When I tried connecting to my database on MongoHQ from localhost, it encountered such an error:
Mongo::ConnectionFailure at /
failed to connect to any given host:port
...
(1.9 on Windows)
Reproducing:
require 'yaml'
s = YAML::load("\xEC\x86\x8C\xEB\x85\x80\xEC\x8B\x9C\xEB\x8C\x80")
# => "∞åîδàÇ∞ï£δîÇ" or "소녀시대", depending on your terminal's unicode support
s_interned = s.intern
s_interned.class # => Symbol
s_yamld = s_interned.to_yaml
# => "--- \":\\xEC\\x86\\x8C\\xEB\\x85\\x80\\xEC\\x8B\\x9...