ruby

What testing frameworks are used for Rails?

I am new to rails, but not to ruby, and the book I am reading (Pragmatic Programmers Agile Dev. with Rails 4th Ed.) just introduced me to unit tests in Rails. The book showed me the default rails testing suite (a subclass of Test::Unit). In the Rails community, is this the main testing framework that is used, because I use RSpec when doi...

ruby string escape when adding

In Ruby on Rails,I got a string number is made of 3 parts : prefix , counter , suffix In model Setup: def self.number prefix = setup.receipt_prefix.blank? ? "" : setup.receipt_prefix.to_s counter = setup.receipt_counter.blank? ? "" : setup.receipt_counter+1 suffix = setup.receipt_suffix.blank? ? "" : setup.receipt_suffix.to_s each i...

Ruby on Rails 3 and Google Book Search

I'm trying to get started using the Google Data API for Google Book Search in my Ruby on Rails 3 application, and I don't even understand how to get started. What gems do I need? What do I need to do in order to do something simple like searching for books with a title of Foobar? ...

.finding on a method in ActiveRecord

I'm using ActiveRecord and Ruby (outside of Rails) to track some statistics. I added a method (total_cost) to one of my models to do calculations using a couple of the columns in the current model as well as a column from another model. I'd really like to be able to use some of ActiveRecord's provisions for math (averaging, sums) and ...

Page navigation problem in Rhomobile Rhodes app

On a page in a model, I'm showing two links 'Choose Picture' and 'Take Picture'. I'm suceessfully successfully returning to that page after choosing picture and the chosen image is being shown correctly. However, when I click 'Take Picture', camera opens up, I take picture, the calling page loads with image shown and then immediately the...

XML schema validation and pattern errors

I have a problem validating a perfectly valid XML with it's schema file in Ruby. It works OK on my development machine (OS X 10.6) but fails everytime on the production system (Debian 4.1). The part of the XML that gives errors is this: <ROUNDINGS>-0.02</ROUNDINGS> And the XSD pattern is this: <xsd:element name="ROUNDINGS"> <xsd:s...

"Array to Hash" transform in Ruby

Hello. I need to transform ["a", "b", "c", "d"] to {:a => {:b => {:c => "d" }}} ? Any ideas ? Thanks ...

How do I run rake tasks within my rails application.

What I want to do: In a model.rb, in after_commit, I want to run rake task ts:reindex ts:reindex is normally run with a rake ts:index ...

Rmagick write text in Images

Hi, Can someone please spend me some line of codes, that add a text at the bottom of an image? I want to use Rmagick but I'm open for other tools also. thank you! ...

intersperse function in ruby ?

Hi I'm looking for an equivalent of the haskell instersperse function in Ruby. Basically that add something (like a separator) between each element of a list. intersperse(nil, [1,2,3]) => [1,nil,2,nil,3,nil,4]. I'm not asking for any code (I can do it , and I'd probably have done it before you read the question). I'm just wondering ...

How to get all class names in namespace in ruby?

Hi, I have an Foo module, that it is namespace for many classes ie: Foo::Bar, Foo::Baz an so on. Is there an way to return all class names namespaced by Foo? ...

Sinatra: executing code on starting or restarting my app

Hi! I want to execute some ruby code on the start of application. Actualy this is some SQL for creating all my tables if they are not already exists. Nowaday I should run my sql manualy (creating new tables ordinary), but I want to write somewhere in my helloworld.rb sql, which will execute sql once my app is started or restarded. Th...

Ruby bring window to foreground

I am using Ruby 1.9.1p430 (2010-08-16 revision 28998) on MS Ws7 with MS Office 2010 I have launched a copy of Word from Ruby using WIN32OLE: wd = WIN32OLE.new('Word.Application') All works fine, I can manipulate my document as required. However, the Word window is in the background and I would like to bring it to the foreground so th...

How to stop with debugger on NoMethodError in NetBeans when running Ruby?

Netbeans 6.9 JRuby 1.5.0 rails 2.3.4 Error example: NoMethodError in Report#week Showing app/views/report/_list_record.html.erb where line #26 raised: You have a nil object when you didn't expect it! The error occurred while evaluating nil.sorting .... I can set up breakpoints, the debugger works fine. But when I have a NoSuch...

Is it possible to identify aliased methods in Ruby?

Often within the console, I'll interrogate an object pp obj.methods.sort #or... pp (obj.methods - Object.methods).sort In Ruby it's pretty common for a developer to provide aliases for methods. I am wondering if there is a reflective way of identifying aliases so that I might be able to display aliased methods, something like... arr...

push Rails3 on Heroku. can not find mysql gem

hi, i'm getting an error when pushing to heroku using rails 3. I'm on windows with ruby 1.8.7 Administrator@WIN-DQC3IH63U7C ~/nasha (master) $ heroku rake db:migrate rake aborted! no such file to load -- mysql /disk1/home/slugs/280561_9c64ba2_1741/mnt/Rakefile:4 (See full trace by running task with --trace) (in /disk1/home/slugs/280561_...

How do I map unique values from a multi-level array to a hash of value=>array?

I have an array that looks something like this: [[100, "one"], [101, "one"], [102, "one"], [103, "two"], [104, "three"], [105, "three"]] What I would like to do is create an array of hashes that looks like this [{"one" => [100,101,102]}, {"two" => [103]}, {"three" => [104,105]}] The number portion will always be unique, the ...

Distinguishing between nginx and thin

This is a newbie question around nginx and thin in the rails environment. In reading/learning on rails I frequently hear about nginx and thin being a great combination for a rails site. In reading the descriptions of each, they both describe themselves as web servers, so I'm a little confused at what the combination brings to the tabl...

how to display current date in mm/dd/yyyy format in rails

In my view i want to diplay current date in mm/dd/yyyy format ...

How many classes is too many? Rails STI

I am working on a very large Rails application. We initially did not use much inheritance, but we have had some eye opening experiences from a consultant and are looking to refactor some of our models. We have the following pattern a lot in our application: class Project << ActiveRecord::Base has_many :graph_settings end class Graph...