ruby

Identify the referrer domain in rails

Hi All, I have a web site which has 2 domains ex : www.site1.com www.site2.com (which will forward to www.site1.com with domain masking) www.site1.com is where the actual web server rungs www.site2.com is just a domain name forwarder and I use mask to make the user feel he/she is in www.site2.com even though he/she is in www.sit...

Convert HTML to Textile in Ruby?

Is there a ruby library like RedCloth that converts HTML to Textile? ...

SOAP calls using EventMachine

Is there any way to make non-blocking SOAP requests within EventMachine? I'm creating a ruby application which interacts with the google adwords api (which is SOAP based), using the adwords4r gem. The application uses EM to receive messages over a stomp connection, and then processes those messages by making SOAP calls to the adwords a...

update ruby to 1.8.7

I'm working on a project that i have to use ruby 1.8.7. I'm using today, ruby 1.8.6 + Mac OSX Darwin. This ruby 1.8.6 was installed with the OS, it's a developer package from Apple. My question is: how can i update this package? if i run ports, it dont find my current installed package and install a new ruby version, with different paths...

ruby - if string is not contained within an array

I only want to output one anchor here. If the current_page is in the array I get two (.html and -nf.html). If it is not in the array I get as many anchors as there are items in the array. I am using StaticMatic. - if page_options[:current_index] < page_options[:total_index] && page_options[:current_index] > 0 // loop through the ...

mysql + ruby = nightmare

Ok, I'm done. I can't understand why I got this error with: rake features It cant' be I can't connect to mysql cause the: rake db:migrate works perfectly. I keep having this error: rake features --trace (in /Users/myname/Projects/rails_app) ** Invoke features (first_time) ** Invoke db:test:prepare (first_time) ** Invoke db:abort_...

Calling initialize when loading an object serialized with YAML

Is it possible to force Ruby to call an initialize method when using YAML.load_file? I want to call the method in order to provide values for instance variables I do not serialize. I know I can factor the code into a separate method and call that method after calling YAML.load_file, but I was wondering if there was a more elegant way t...

Ruby: Time difference in percentage?

How would I, for example, find out that 6pm is 50% between 4pm and 8pm? Or that 12am Wednesday is 50% between 12pm Tuesday and 12pm Wednesday? ...

flickr-fu simple example not working

Hi, I'm using flickr-fu gem within a rails application for flickr api integration. I'm following the sample code for setting up a web app shown below: def flickr_create flickr = Flickr.new(File.join(RAILS_ROOT, 'config', 'flickr.yml')) redirect_to flickr.auth.url(:read) end def flickr_callback flickr = Flickr.new(F...

Turning a hash into a string of name-value pairs

If I'm turning a ruby hash into a string of name-value pairs (to be used in HTTP params, for example), is this the best way? # Define the hash fields = {"a" => "foo", "b" => "bar"} # Turn it into the name-value string http_params = fields.map{|k,v| "#{k}=#{v}"}.join('&') I guess my question is: Is there an easier way to get to http_...

How to call a C# dll in ruby?

How to call a C# dll in ruby? ...

How do I enable SASS line numbers in CSS output?

How can I enable line numbers in CSS output if I am using SASS? I found an article but I didn't quite understand where to make the modifications http://pivotallabs.com/users/damon/blog/articles/765-standup-04-07-2009-we-have-questions#comments Could you help me? ...

String comparison in Ruby on Rails unit-test

Hi, my Ruby On Rails unit-test fails in a simple string comparison and I can't figure out why. In the model TestItem, I have doc = REXML::Document.new(data) @bugtitle = doc.root.get_text("/bugzilla/bug/short_desc") where data is a xml-string returned by a Net::HTTP::post request. The data looks good, and if I output @bugtitle it cont...

Netmask to CIDR in ruby

I've been using the ip-address gem and it doesn't seem to have the ability to convert from a netmask of the form 255.255.255.0 into the CIDR form /24 Does anyone have an ideas how to quickly convert the former to the latter ? ...

Vital Ruby concepts to learn before I jump into Rails?

Disclaimer - Ruby is the first language I've ever learnt. I don't have any CS background. I've worked through "Learn to Program" by Chris Pine which has been enjoyable and I now understand the basics pretty well. The next recommended book would be "Programming Ruby 1.9" (the next PickAxe). From what I've read it's just a massive referen...

Rails - Why can't I use a method I created in a module in my tests?

I created a module in lib directory and I can freely call the various methods it contains throughout my Rails app (after adding include ModuleName) with no problems. However when it comes to tests, they complain no such methods exist. I tried including the module into my test helper with no luck. Can anyone help. 4) Error: test_valid_s...

How to include unit tests in a ruby module ?

I'm trying to include the unit tests for a module in the same source file as the module itself, following the Perl modulino model. #! /usr/bin/env ruby require 'test/unit' module Modulino def modulino_function return 0 end end class ModulinoTest < Test::Unit::TestCase include Modulino def test_modulino_functio...

Ruby Datamapper table inheritance with associations

I started learning Datamapper and what I liked about it was that I can write my models with real inheritance. Now I wonder, if it is possible to be more advanced about this: class Event include DataMapper::Resource property :id, Serial property :begin, DateTime property :type, Discriminator end class Talk<Event property :tit...

Dynamically Create Arrays in Ruby

Is there a way to dynamically create arrays in Ruby? For example, let's say I wanted to loop through an array of books as input by a user: books = gets.chomp The user inputs: "The Great Gatsby, Crime and Punishment, Dracula, Fahrenheit 451, Pride and Prejudice, Sense and Sensibility, Slaughterhouse-Five, The Adventures of Huckleberry...

Which widgets to use for a messenger

Hello I'm currently learning to program Ruby with GUI. And has chosen wxruby. But has never used wxwidgets before. So my question is, which widgets do I use for the users list, the message list (scrolling) and the input area ? Want to be able to choose font, color and use icons etc in the input area and the message list. And hoping to ...