ruby

Facebook api for different environments.

I've an application integrated with Facebook Connect. My application is deployed on different environments (production, staging, development) with different domains. Is there a way to set up Facebook app, so that it work with all my environments? Or should I create separate facebook apps for each env? ...

Rails shoulda and factory_girl setup

I have installed both shoulda and factory_girl, I can run shoulda just fine, but when I add this: require 'factory_girl' Factory.define :user do |u| u.mail '[email protected]' u.pass 'secret' end to my test/test_helper.rb I'm getting this error: /test/test_helper.rb:1:in `require': no such file to load -- factory_girl (LoadError)...

Rubygems optional dependencies

How do I add optional dependencies to rubygems, as it does not support it? Use cases: I have a library that does either depend on Backports, Extlib, Facets or ActiveSupport. In the past I just did not add any of this dependencies, as people could choose (read: it would play nicely with whatever they were using), but people complained ...

Partials vs for loop — best practices

In coding up your view templates you can render a partial and pass an array of objects to be rendered once per object. OR you can use a For blank in @blank loop. How do you decide when to do which? It seems that if you use a partial for every iterable object you will end up having to modify tons of separate files to make changes to poten...

Refactoring multiple if statements for user authentication with subdomains

...

Liquid templates - accessing members by name

I'm using Jekyll to create a new blog. It uses Liquid underneath. Jekyll defines certain "variables": site, content, page, post and paginator. These "variables" have several "members". For instance, post.date will return the date of a post, while post.url will return its url. My question is: can I access a variable's member using anoth...

XSLT transformations in Ruby and JRuby

Simple question: are there any solid XSLT libraries that work in both Ruby and JRuby? REXML works in both, but does not have XSLT support. ruby-xslt doesn't work in JRuby. The latest Nokogiri betas do support JRuby, but the support is still buggy and throws occasional NullPointerExceptions for XML input that works fine in Ruby. (In pa...

Help me refactor my World Cup Challenge Script

I am setting up a World Cup Challenge between some friends, and decided to practice my Ruby and write a small script to automate the process. The Problem: 32 World Cup qualifiers split into 4 tiers by their Fifa ranking 8 entries Each entry is assigned 1 random team per tier Winner takes all :-) I wrote something that suffices yet...

Ruby custom class to and from YAML;

Hi. I'm having trouble deserializing a ruby class that I wrote to YAML. Where I want to be I want to be able to pass one object around as a full 'question' which includes the question text, some possible answers (For multi. choice) and the correct answer. One module (The encoder) takes input, builds a 'question' class out of it and app...

Extract URLs from text using Ruby while handling matched parens

URI.extract claims to do this, but it doesn't handle matched parens: >> URI.extract("text here (http://foo.example.org/bla) and here") => ["http://foo.example.org/bla)"] What's the best way to extract URLs from text without breaking parenthesized URLs (which users like to use)? ...

Ruby Large HTML emails getting error, limit to header size

def mailTo(subject,msg,folks) begin Net::SMTP.start('localhost', 25) do |smtp| smtp.send_message "MIME-Version: 1.0\nContent-type: text/html\nSubject: #{subject}\n#{msg}\n#{DateTime.now}\n", '[email protected]', folks end rescue => e puts "Emailing Sending Error - #{e}" end end when the HTML is VERY large I get this exception...

Can I pass variables to eval?

Hi, I am trying to pass a variable to a dynamically declared method like: eval(def test(name) puts name end test 'joe') but it does not work. Is there a way to do this? ...

ruby - find and replace in a string for commonly used street suffix

The post office actually publishes a list of commonly used street suffixes in addresses: http://www.usps.com/ncsc/lookups/abbr_suffix.txt I want to take this list and make a ruby function that takes a string, takes the last word ("183 main strt".split[' '].last) and if it matches any of the commonly used street suffixes ("strt"), repla...

Sinatra Gem install error

I have been trying to install sinatra in a macbook running leopard system, and I am not able to do it. I get the following error. MacBook:rubygems-1.3.7 lakshmanan$ gem install sinatra WARNING: RubyGems 1.2+ index not found for: http://rubygems.org/ RubyGems will revert to legacy indexes degrading performance. Bulk updating Gem sourc...

how do I base encode a binary file (JPG) in ruby

I have a binary files which needs to be sent as a string to a third-party web-service. Turns out it requires that it needs to be base64 encoded. In ruby I use the following: body = body << Base64.b64encode(IO.read("#{@postalcard.postalimage.path}")) body is a strong which conists of a bunch of strings as parameters. Does this...

unable to update gems on mac osx - Gem::RemoteFetcher::FetchError

Jon-MacBook-Pro:rubygems-1.3.7 jon$ sudo gem install rails Password: ERROR: While executing gem ... (Gem::RemoteFetcher::FetchError) SocketError: getaddrinfo: nodename nor servname provided, or not known (http://rubygems.org/gems/activesupport-2.3.8.gem) ...

Logging a certain event only once in ruby

Are there any logging frameworks in ruby that allow you to log a specific event type only once? logger = IdealLogger.new logger.log(:happy_path, "We reached the happy path") # => logs this message logger.log(:happy_path, "We reached the happy path yet again") # => Doesn't log this logger.log(:sad_path, "We've encountered a sad path!") #...

Ruby library for Flickr API?

Is there a solid, production ready library in Ruby that interacts with the Flickr API? I found a few by googing, but their states don't impress me much. I'm looking for something along the lines of flickrapi for Python, with nice documentation. ...

Globalize2 and migrations

Hi, I have used globalize2 to add i18n to an old site. There is already a lot of content in spanish, however it isn't stored in globalize2 tables. Is there a way to convert this content to globalize2 with a migration in rails? The problem is I can't access the stored content: >> Panel.first => #<Panel id: 1, name: "RT", description: "...

Can I run our tests using redgreen without changing our source code?

I'd like to use redgreen (or similar) to colour the output of our tests, but I don't want to force it on everyone else. Is there a way for me to use it without changing our source code? ...