ruby

Ruby - HornetsEye

I am compiling HornetsEye on Linux Mint 9. And I think it should be successful. When I tried 'require 'hornetseye'' in irb, I got the following message. RuntimeError: /usr/lib/ruby/1.8/i486-linux/RMagick2.so: This installation of RMagick was configured with ImageMagick 6.5.5 but ImageMagick 6.5.7-8 is in use. from /usr/lib/ruby/1.8...

[Ruby] How do I access the string name of the parent class from a class method in a extended class or included module.

My problem basically looks like this: module Foo class Bar def self.who self.class.to_s end end end class World < Foo::Bar end When I call World.who I don't get "World" as a result, I get "Class". Some quick Googling didn't yield anything useful, so hence I'm here hoping someone will know how to get the correct cla...

Sinatra and Datamapper - inserting data to a one to many relationship table

I have the following. Each article has a title and a body and also up to three urls. I would want to store the urls in a different table. Therefore in my form, i've a field for the urls. However they are not working, only the article fields get entered into the database. how should i specify them? Could any kind soul help me out with thi...

Ruby unit test :run a test class from the main class

In Ruby unit testing can I run a test class from another class for exa class Foo < Test::Unit:: TestCase test_abc() test_bnd() Now i want to run this above test suite from my main class so how could i do it I tried using runner but dono wat should be argument to the run method Test::Unit::UI::Console::TestRunner.run(FOO) , R...

RVM doesn't switch Rubies

I'm running Ruby 1.9.1p243 on CentOS, and I decided to install rvm to handle upgrading to 1.9.2 or downgrading to 1.8.7 (whichever turns out to work better for rails3). I followed the instructions here: http://rvm.beginrescueend.com/rvm/install/ and everything installed correctly. I was able to compile and install Ruby 1.8.7, 1.9.1, and...

How to create this Ruby on Rails form?

I have a route that looks like the following: map.newsletter '/newsletter', :controller => "newsletter" , :action => "newsletter_signup" There is also a NewsletterController and a Newsletter model. The thing is, I wanted to keep my controller down to one simple method, newsletter_signup. In there I simply check if the request is of ty...

Ruby on Rails: Can you put Ruby code in a YAML config file?

Sorry if this is a dumb question, but I am new to Ruby on Rails. I would like to do something like this in my amazon_s3.yml config file: access_key_id: ENV['S3_KEY'] secret_access_key: ENV['S3_SECRET'] ...but I know this isn't working. Not sure if it is even possible, but can you put Ruby code in a YAML file? ...

Why does this code print the same thing twice?

I am trying to write some small timeout code: t = Thread.new { sleep 3 } # <- The thread that will do stuff. Thread.new { sleep 2; t.kill; p 'hi!' } # <- The thread that will kill it after two seconds. t.join If the first thread completes it's job within two seconds, it will stop, and the main thread will have nothing to do. This will...

How do you stop a MongoDB search from being applied recursively to the key-value tree?

Imagine I have this object (written with Ruby literals) stored in a MongoDB: {"tags" => ["foo", "bar"], "jobs" => [{"title" => "Chief Donkey Wrangler", "tags" => ["donkeys"]}] } Now, I want to search for objects based on the tags on the first level of data, not the second. I can write a query like this (using the Ruby MongoDB librar...

How to use named Machinist blueprints in Cucumber with Pickle

I noticed this little tid-bit in the readme for pickle: (The latest version of pickle supports multiple blueprints, for earlier versions of machinist use pickle <= 0.1.10) I'm running in to a situation where I want to create a user with admin privileges. I've got two machinist blueprints: User.blueprint do first_name last_name ...

In Class methods, why does one method seem to accept instance variables and another doesn't?

In the following code example, why does the second (sheetplus) method seem to pick up the instance variables @name and @occupation fine, but the first (sheet) method return nil? I feel like I'm missing something deadly obvious, but I am basically the world's worst Ruby programmer. class Test def initialize(name, occupation) @name = n...

Reading an uploaded file into a File object in a controller method-"can't convert Tempfile into String"

So Im trying to implement a file upload functionality where when a user uploads a file, I can read that into a File object and process it accordingly: def create name = params[:upload]['datafile'].original_filename directory = "public/data" # create the file path path = File.join(directory, name) # read the file Fil...

what is the best programming language for selenium?

I am planning to learn selenium, what would be the best language to learn along with selenium? Perl or Ruby or others? ...

Strange Rails 2 Routing Question

I saw this in a rails 2 vs 3 comparison pdf lecture and I'm not sure what's going on with the preview and archived flags. post.resources :comments, :member => { :preview => :post }, :collection => { :archived => :get } Any ideas? ...

can't dup NilClass - Error

I am stuck in this error for quite sometime now and have hit a dead end. I get this totally unhelpful error can't dup NilClass This is the situation. I have one class which is in a relationship with another. Say class Parent end class Child < Parent unloadable :has_many :parents, :foreign_key => "child" end The err...

Ruby, SSLSockets, and Apple's Enhanced APN message format

I'm trying to implement support for Apple's enhanced Push Notification message format in my Rails app, and am having some frustrating problems. I clearly don't understand sockets as much as I thought I did. My main problem is that if I send all messages correctly, my code hangs, because socket.read will block until I receive a message. ...

"Ago" date/time functions in Ruby/Rails

Hi - I was wondering, if theres a way in rails to calculate time stamp like - half a minute ago, 2 minute ago, 1 day ego etc. Something like twitter real time date stamp. I want to know if ruby/rails has a pre-built function for such date-time conversion?? ...

help with ruby on rails

I have installed Ruby. When I start the Mongreal server I get this error message the program cant start because msvcrt-ruby18.dll is missing I even downloaded the file msvcrt-ruby18.dll, but no use I googled it, but cannot solve the problem ...

How do I use this Ruby code?

I found this Ruby code to help use the Imageshack API on CodeSnippets. I'm new to Ruby on Rails, so I know how to use models, views and controllers generally, but I'm not sure how I just use this code. Would it be a module? Thanks for reading. Usage: pic_online = ShackMirror.new(local_path_of_pic) pic_online.url # => retu...

mongodb find in embedded document hash mongomapper

hi I have a menu class and that have many menu_items and a menu_item class that is embedded docuemnt. I can get a specific menu like menu = Menu.find_by_name("menu 1") then i want to find and update or create the menu_item that matches a specific category id. I want to create the menu item if category id is not found in menu items...