I am creating non-namespaced classes dynamically.
I have seen an example where this creation is done within the Object class:
class Object
for elem in ARRAY
sub_class = Object.const_set(elem.to_s.camelize, Class.new(SuperClass))
sub_class.class_eval do
def initialize(*args, &block)
...
super *args, &b...
I have several models: ContactEmail, ContactLetter, ContactCall
My controller doesn't know what is being passed into it. It only knows it as an event (so event can be specific instance of ContactEmail, ContactLetter, ContactCall)
Each of these has a different attribute. ContactEmail has email_id; ContactLetter has letter_id, Contact...
I have found that reading 64 contiguous memory locations (elements) using modbus is the most efficient way of retrieving information over Modbus using the rmodbus library.
My goal is to log the read information in a simple database that can be mined to generate graphs and tables of data on a webpage and store the most current value in ...
Hey!
I have models club and course where a course belongs to a club and and a club has many courses.
When I load a club, I also want to load it's associated courses, but I only want to load those that meet a conditional test (approved? == true).
It is straightforward how to do this if I were working directly with the courses:
@course...
I am trying to set the :host for action mailer default url options.
I have the below set in all the environment files
config.action_mailer.default_url_options = {
:host => "localhost"
}
I want to make it more dynamic by providing the request host.
when I try to set it by
config.action_mailer.default_url_options = {
:host => ...
Hi there,
I'm on Rails 3,and I have a SQL query composed of a few joins that I've built up in Arel. I want to run this query from a method in one of my models, but I'm not sure of how to do this. The arel object turns out to be of type Arel::InnerJoin, and I want to retrieve an array of all objects returned from that query. Do I run Mod...
Hello.
My code must parse Vcard 2.1 format.
I am using vpim(there are no other libs)
When I run Vpim::Vcard.decode(data) I get error:
undefined method `each' for #<String:0x0000000928e778>
StackTrace:
NoMethodError (undefined method `each' for #<String:0x0000000928e778>):
vpim (0.695) lib/vpim/rfc2425.rb:82:in `unfold'
vpi...
What's the Rails 3 replacement for ActiveRecord::Errors?
In Rails 2.3.8, this is an object:
>> ActiveRecord::Errors
=> ActiveRecord::Errors
In Rails 3.0.0rc, you get a NameError:
>> ActiveRecord::Errors
NameError: uninitialized constant ActiveRecord::Errors
from (irb):2
I'm trying to make the wizardly generator work with Rails 3....
Is there a way to return only active projects using Basecamp's API? No matter what I try I always get back my entire list of projects, and it's HUGE.
Here's what I think should work:
Basecamp.establish_connection!('myhost.basecamphq.com', 'my_user', 'my_pass')
@projects = Basecamp::Project.find(:all, params => { :status => 'active' } )...
Hi there,
I'm having a problem testing the following model:
class Bill < ActiveRecord::Base
belongs_to :consignee
before_save :calc_rate
def calc_rate
self.chargeableweight = self.consignee.destination.rate * self.weight
end
end
The consignee model:
class Consignee < ActiveRecord::Base
belongs_to :destination
has_ma...
I've tried to use the recommended way (from the Rails Guides) to test routes generated in plugins, but the test keeps failing.
What's odd is that if I reload the routes AFTER creating the route (or so I think), the test fails, but if I let the test go through once (e.g. using autotest), then the route gets recognized on subsequent attem...
I have currently the following setup:
An object graph of all requests read from an application server log file.
Each line is represented as a RequestPart, with the following information: start time, stop time, tier, application part that is done.
I would like to draw / to graph something that shows the following:
Show different col...
I have the following:
class Test
@@a = 10
def show_a()
puts "a: #{@@a}"
end
class << self
@@b = '40'
def show_b
puts "b: #{@@b}"
end
end
end
Why does following work:
Test.instance_eval{show_b}
b: 40
=> nil
But I can't access @@b directly?
Test.instance_eval{ @@b }
NameError: uni...
I'm writing a script that makes some trivial changes and then commits them to git. Because these are trivial changes, I want to do git commit --amend whenever I can get away with it -- specifically, when an amend won't "mess up" any other branches' history. If an amend would mess up another branch, I want to do a standard git commit inst...
I am having trouble configuring Sinatra to use Bundler. I am confused as to where Gems should be being installed? I've read both this question and this documentation.
My Gemfile looks like:
source "http://rubygems.org"
gem "sinatra"
gem "amazon-ec2"
My config.ru looks like:
require "rubygems"
require "bundler"
Bundler.setup
require ...
i want set the rails plugin devise'reset_password_instructions to delayed_job..but i tried many ways is fail.
i found a function password_controller#creat they have
self.resource = resource_class.send_reset_password_instructions(params[resource_name])
i think the sentence used for send email to reset password.
i want alter it like ...
has_attached_file :image, :storage => :s3, :s3_credentials => "#{RAILS_ROOT}/config/s3.yml", :path => "/:style/:filename"
What is this :path => "/:style/:filename"`
I also want to to include the style for this attached image, is that what the :path is?
the style I want is this: :styles => { :medium => "275x275>", :thumb => "175x155>" }...
Sometimes you can see:
do_this do
available_method1 "arg1"
available_method2 "arg1"
end
When I use the block from do_this method then I get some methods I could use inside that block.
I wonder how this is accomplished? How does the code look like behind the scenes?
I want to be able to provide some methods through a block.
...
Hi,
I'd like to view each Project by Client, but unsure how to use Datamapper to get this information out. I have my relationships setup like this:
class Client
property :id, Serial
property :name, String
has n, :projects, :foreign_key => "company_id"
end
class Project
include DataMapper::Resource
property :id, Serial...
Running latest Ruby in Windows 7.
I want to be able to be able to execute code from cmd by just typing code.rb
Right now I have to type ruby code.rb
Also, when I double click the code.rb file, a command prompt briefly pops up and then closes - too quick for me to read what it says.
I have tried associating .rb with ruby.exe using ftyp...