I generated a model file but then chose to let it single table inherit from another model. I had to run no migration, because the columns all were already there.
Now whenever I want to run tests, I get complaints that the table for the model does not exist.
So I have Product < Article < ActiveRecord::Base, product has no own table (doe...
In my Sinatra app, I'm using a MongoDB with Grid to store book covers on Heroku. I want to be able to associate these with the books in my ActiveRecord-driven primary database. Currently, I'm downloading the image from Google Books, storing it in the MongoDB, and storing the BSON::ObjectID object into the database as a string.
When I go...
I have recently tried sharping my rails skills with this tool:
http://github.com/edgecase/ruby_koans
but I am having trouble passing some tests. Also I am not sure if I'm doing some things correctly since the objective is to just pass the test, there are a lot of ways in passing it and I may be doing something that isn't up to standard...
Could I use the Mongo client shell queries/commands from inside Ruby?
I know there is the Ruby driver DSL, but I was thinking about something similar to running a SQL query from within PHP.
Just for the sake of knowing.
...
I would like to extend an Ruby Array object, to make it returns Array.new if it's nil.
My solution:
Overwrite [] and at.
module NullSafeArray
def at(index)
value = super
return Array.new if value.nil?
value
end
def [](index)
value = super
return Array.new if value.nil?
value
end
end
The problem:
Th...
I try to output the german setence containing the letter "ü" in escaped form (ascii 252, octal 374, hex 0xfc) using the following code:
pp "Test \374"
pp "Test \374".encode("UTF-8")
But using ruby 1.8.7 I get:
"Test \374"
"Test \374"
Using ruby 1.9.2 outputs:
"Test \xFC"
"Test \xFC"
How can I get ruby (1.8.7 + 1.9.x) to output "Test...
I have the following as part of a class
def to_s
i = 0
first_line? = true
output = ''
@selections.each do | selection |
i += 1
if first_line?
output << selection.to_s(first_line?)
first_line? = false
else
output << selection.to_s
end
if i >= 5
output << "\r"
...
I am writing the scripted GUI tests for a system which I do not have access to its source code; and I want to invoke the methods and access the properties of an OCX control (specifically the MSFlexGrid control) as I could not find any other way of finding out the number of rows and columns, as well as the data values in each cell, in the...
Hi all,
I would like to call a Ruby script when a user uploads an image to my Drupal content-type. I have a CCK image field that serves as the main image, and ImageCache takes care of resizing and creating thumbnails for me.
I have a Ruby script that does some transformations to the image, however I don't exactly know how to call it (...
I need to refer to a controller method from a cache observer, How can I make it?
...
I have some date objects that are Date of the Date class, and others that are Time.
The trouble is is that when I parse them to load them chronologically, they list first as the Times, followed by the Dates.
This is the code that loads them :
query.any_of do |any_of|
any_of.with(:date).greater_than((params[:current_date] || Date...
I have a hash of dates to money, and I need to put new money deposits inbetween a set of dates.
so, lets say my hash is
{"000000001" => "0.00", "000000002" ="12.34", "000000010" => "5.95"}
and I want to insert 000000008, 54.34 then my resulting hash should be
{"000000001" => "0.00", "000000002" ="66.68", "000000010" => "5.95"}
*...
I have a hash
hash = { 1=> { 0=> 'apple', 1=> 'tree'... ....}, 2=> {.....}}
I want to grab the 0 for all hashes within the hash. I know there is a transpose for array, but there any way to do this with a hash easily?
...
I'm using compass 0.10.4
I'm running a compass command and I want it to put it's output to the
server when I run a watch instead of to the project directory.
Is there any way of specifying an absolute path instead of a path
relative to the directory you want the css output to?
I'm trying to have my compiled css output to the directory...
In modern versions of ActiveRecord you can define any number of before_validation handlers using a simple declaration:
class MyModel < ActiveRecord::Base
before_validation :do_something
before_validation :do_something_else
end
Using Sequel it looks like the only way you can do this is similar to the older ActiveRecord method:
cla...
Admittedly, I'm a Nokogiri newbie and I must be missing something...
I'm simply trying to print the author > name node out of this XML:
<?xml version="1.0" encoding="UTF-8"?>
<entry xmlns:gd="http://schemas.google.com/g/2005" xmlns:docs="http://schemas.google.com/docs/2007" xmlns="http://www.w3.org/2005/Atom" gd:etag="">
<category te...
So, I'm positive I once did a 'sudo' bundle install' out of desperation, which I now understand is a no-no. But now, when i try to run 'bundle install', I get the following error:
Installing culerity (0.2.12) /Library/Ruby/Site/1.8/rubygems/installer.rb:294:in `generate_bin': You don't have write permissions into the /Library/Ruby/Gems...
Hi everyone,
In my Item controller, I wish to add a transient (i.e. non-persistent) attribute to my model object before rendering it as JSON.
def show
@item = Item.find(params[:id])
@item.comment = "some comment"
render :json => @item
end
My Item class looks like this:
class Item < ActiveRecord::Base
attr_acc...
I was going through the exercises at http://rubykoans.com/ and I was struck by the following Ruby quirk that I found really unexplainable:
array = [:peanut, :butter, :and, :jelly]
array[0] => :peanut #OK!
array[0,1] => [:peanut] #OK!
array[0,2] => [:peanut, :butter] #OK!
array[0,0] => [] #OK!
array[2] => :and #OK!
array[2,2] ...
hi
i want to create product comparison site expecting good no of user hits (100 + concurrent users)
i am from dot net background(LOB Application),i haven't done much research for good programming platform for such user oriented website with some user generated content , i have following options
1: c# asp.net Ajax
2: silver light
3: ph...