I have a scenario where I am trying to do a proof of concept using Rails on a legacy db2 database to get buy off that it is a viable option platform for us to use for current and future development.
All of our tables have a primary key which is defined as char for bit data, which is binary. Is there any way I can define a mapper to c...
Say I have an array like this:
["white", "red", "blue", "red", "white", "green", "red", "blue", "white", "orange"]
I want to go through the array and create a new array containing each individual color and the amount of times it appeared in the original array.
So, in the new array it would report that "white" appeared 3 times, "blu...
So I'm a newbie at rails and I'm trying as best as I can follow tutorials that abound the web. So I have three tables.
class CreateAuthors <
ActiveRecord::Migration def self.up
create_table :authors do |t|
t.string :name
t.string :email
t.timestamps
end
end
de...
Here's a Ruby OO head scratcher for ya, brought about by this Rails scenario:
class Product < ActiveRecord::Base
has_many(:prices)
# define private helper methods
end
module PrintProduct
attr_accessor(:isbn)
# override methods in ActiveRecord::Base
end
class Book < Product
include PrintProduct
end
Product is the base cla...
Which APIs are necessary to make a file downloader in ruby programming language?
...
If I want to have a prompt on the terminal with a default value already typed in, what library should I use?
Ruby's standard Readline.readline() lets me set the history but not fill in a default value (as far as I can tell, at least)
Something like:
code:
input = Readline.readline_with_default('>', 'default_text')
console:
> def...
I have a variable, start_time:
(rdb:5) start_time.class
ActiveSupport::TimeWithZone
(rdb:5) start_time
Tue, 23 Feb 2010 14:45:00 EST -05:00
(rdb:5) start_time.in_time_zone(ActiveSupport::TimeZone::ZONES_MAP["Pacific Time (US & Canada)"]).zone
"PST"
(rdb:5) start_time.in_time_zone(ActiveSupport::TimeZone::ZONES_MAP["Pacific Time (US &...
here are the requirement from marketing people:
1. they want to be able to setup google adwords and being able to create a landing page, select a template layout, and able to fill in matching title and description. Unique, readable URL is important as well.
2. they want to be able to modify static pages on the site, e.g. about us, FAQs, ...
I have a working HABTM association between the models
Posts and Users... the posts_users table is as advertised and both have the necessary has_and_belongs_to_many in their model.rb
And if I use User.find(1).posts it will find all the posts with the valid username
My question is how to deal with this situation.
I want to use
user.po...
I'm one of those developers who isn't using TextMate with any of his Ruby/Ruby on Rails work. My particular loyalty in this arena lies with vim. What are your favorite tips/tricks for using vim with Ruby and/or Ruby on Rails to make you as efficient as possible when working?
...
My hosting company requires me to put #!/usr/local/bin/ruby at the top of every RB file. Is there an easy way to use sed recursively or something that can go through and append this to the top of every rb file?
...
I have a rake task where I do some checks at the beginning, if one of the checks fails I would like to return early from the rake task, I don't want to execute any of the remaining code.
I thought the solution would be to place a return where I wanted to return from the code but I get the following error
unexpected return
...
I need to tell chronic that the format of date is day-month-year is that possible? The data I pass to chronic could also be words today/yesterday/2 days ago.
Currently chronic gives me 2 Dec 2010 instead of 12 Feb 2010 from 12-02-2010
The only solution I can think of is to swap day and month before passing the string to chronic.
requi...
In my application I have a variety of date sequences, such as Weekly, Monthly and Annually. Given an arbitrary date in the past, I need to calculate the next future date in the sequence.
At the moment I'm using a sub-optimal loop. Here's a simplified example (in Ruby/Rails):
def calculate_next_date(from_date)
next_date = from_date...
Hi, I've been looking for a Ruby implementation of Fedex and UPS.
I've been through their documentation, and think it's really overcomplicated (I'm a bit of a ruby "newbie" myself), so was looking for something simpler. I would only like to use the tracking function.
I found a library called shipping (http://shipping.rubyforge.org/), b...
Hello guys,
I've a name of a class stored in var, which I need to create an object from.
However I do not know in which module it is defined (if I did, I would just call getattr(module,var), but I do know it's imported.
Should I go over every module and test if the class is defined there ? How do I do it in python ?
What if I have the ...
The following does not work. The call to resources.next_document within the thread returns nil. The same call without threading works as expected.
Any MongoDB experts out there? :P
resources = db[Resource::COLLECTION].find
number_of_threads.times do
threads << Thread.new do
while resource = resources.next_document
...
Recently I was having a discussion with a friend about Ruby's Proc. You can call a Proc in one of several ways. One way is to invoke Proc.call:
p = Proc.new { |x| "hello, #{x}" }
p.call "Bob"
=> "hello, Bob"
Another is to use braces, Proc.[]:
p ["Bob"]
=> "hello, Bob"
Are there any potential precedence issues here, or are these two...
I have complex form similar to a recent Ryan Bates screencast
The nested elements work fine however. I'm creating or updating a grid of data such as this through a form where the day's prices are the input. My problem begins when they leave one blank. I have the nested_attributes_for option for not saving nils and it works, if they o...
Ok, so we're upgrading a client's legacy code from 2.0.2 to latest rails. Most of the basics were easy to fix, but I can't get to the admin screens. Every time we hit "current_user" we get a "stack level too deep" error.
I've dug deeply into the code (read: flailed around a lot at random) and I've finally narrowed it down to the ActiveR...