ruby

Is Ruby as cross-platform as Java?

You can compile a Java application and run it in any machine where the Java virtual machine is located, independently of the underlying hardware. Since Ruby on Rails was built upon Ruby, I'm concerned if building software in Ruby in any environment is the same or not. There exists versions of Ruby for Windows, Linux and Mac at least. ...

Method to get the client ip address

I'm developing an application where it seems likely that people will attempt to hide what their client IP address is behind a proxy server. Is there a unified way to get what the actual client IP Address is behind the proxy? Looking at the Ruby docs, it explicitly states that request.remote_ip and request.remote_addr both would ...

How do I escape #{ from string interpolation

I have a heredoc where I am using #{} to interpolate some other strings, but there is an instance where I also want to write the actual text #{some_ruby_stuff} in my heredoc, WITHOUT it being interpolated. Is there a way to escape the #{. I've tried "\", but no luck. Although it escapes the #{}, it also includes the "\": >> <<-END #{R...

Model based deletion of CouchDB data in Rails

I want to set up a rake task to fill my CouchDB with fixtures data and have to get rid of the data in the database first. A good example for the whole procedure using MySQL can be found here. This examples contains the following part to delete the data of the model in the MySQL database: # the list of models (pluralized) you want to imp...

Ignore Iconv::IllegalSequence while using Ruby WWW::Mechanize

Hello, I've encountered the Iconv::IllegalSequence error on some web pages when using mechanize lib. Is there a way to make mechanize just omit ill encoded characters and return the "cut" page? I'm aware of the related thread, but I'd rather discard some characters on the page, then re-implement encoding guessing. TIA ...

Exact Target integration with Ruby examples?

Anyone used Ruby or Rails to integrate with Exact Target's API or have a good example of using WSSE with SOAP4r? ...

Getting fields_for and accepts_nested_attributes_for to work with a belongs_to relationship

I cannot seem to get a nested form to generate in a rails view for a belongs_to relationship using the new accepts_nested_attributes_for facility of Rails 2.3. I did check out many of the resources available and it looks like my code should be working, but fields_for explodes on me, and I suspect that it has something to do with how I ha...

Rails Nested Object Forms with Paperclip - paperclip attrs ignored by reject_if

When submitting a nested object form, I can't get it to reject invalid child objects because the reject_if proc doesn't see the Paperclip attribute. Here are the relevant parts of my models & forms: class Stage < ActiveRecord::Base has_and_belongs_to_many :assets, :uniq => true accepts_nested_attributes_for :assets, :reject_if => l...

methods created by attr_accessor are not available to sub classes

http://gist.github.com/172341 ( stackoverflow was breaking the formatting ) In the following case method name created by Human is not available to Boy. Is my understanding correct that attr_accessor methods are not available to subclasses. I need to use superclass to access the method added by attr_accessor. ...

Which 3D engine for ruby

i am looking for a 3D engine for developing a ruby game. i found some like G3Druby or ogrerb. which one is better to use and has better functionality? is there any other engine better than these? ...

How can I get the binding from method_missing?

I am trying to find a way to get the binding from the caller within method_missing in Ruby (1.8), but I can't seem to find a way to do it. Hopefully the following code explains what I would like to do: class A def some_method x = 123 nonexistent_method end def method_missing(method, *args, &block) b = caller_binding ...

Does Pony support SSL/TLS for GMail (Yes!)

Does the Pony gem support e-mail with SSL/TLS? I'm trying to (easily) send e-mail with Google Apps on Heroku. Thanks! After jumping through several hoops, I found a combination of solutions that worked for me: http://417east.com/thoughts/2009/austin/heroku-gmail-sinatra. ...

rspec mock question

I am trying to Mock an object that is being passed into another object, and am having no success. Can someone show me what I am doing wrong? class Fetcher def download return 3 end end class Reports def initialize(fetcher) @fetcher = fetcher end def status @fetcher.download end end describe Reports do before...

How do I wrap up a Ruby C extension in a Ruby Gem?

I can't find many docs on this. How do I package a gem such that the C extension is compiled when the gem is installed? In particular I want to do this: on Linux and MacOSX i would like compile the C extension on gem install on Windows I would like to simply install a precompiled .so any help on this, in particular example source, w...

Creating a created_by column and association with rails?

Sigh... I feel like a big newbie on this one, so lets say I have a few models: class Question < ActiveRecord::Base has_many :answers belongs_to :user end class Answer < ActiveRecord::Base belongs_to :question has_one :user end class User < ActiveRecord::Base has_many :questions has_many :answers, :through => :questions end...

how to get all docs with acts_as_solr

Hi, I'm doing something like this: Item.find_by_solr('name:ab*') and it says it returns 297 results: => #<ActsAsSolr::SearchResults:0xb6516858 @total_pages=1, @solr_data={:docs=>[doc1, doc2, doc3...]}, :max_score=>1.6935261, :total_pages=>1, :total=>297}, @current_page=1> Item.count_by_solr('name:ab*') also returns 297. Yet when ...

Rspec 'should change' with floating point

Is it possible to use RSpec .should(change(...)).by(...) with float numbers and set the compare precision like this: lambda { ...}.should change(unit, :price).by(12.151, 10e-5) Thanks, ...

insert image in .doc using win32ole library of Ruby

Hi all, As the Title suggests, i am trying to find how to insert image in MS Word(.doc file) using ruby Win32Ole api. I have tried the function InsertFile of Range Object but it seems, it is only made for inserting other doc file in our file in question. Does anyone know anything related to this . It will very helpful. ...

Scalable ruby application

I am java developer and heard a lot about ruby. My real question is can we develop large scale enterprise (web) application in ruby ? Because I heard that ruby is good for small application, but like java we can't develop large scale scalable (web) application in ruby. ...

What does "class#method" mean in ruby?

Possible Duplicate: Why are methods in ruby documentation preceded by a pound sign? EDIT: Duplicate of Why are methods in ruby documentation preceded by a pound sign? Hi, I'm trying to learn Ruby for fun at my spare time with the free Programming Ruby book. It is mostly fairly straight forward but I kept seeing notations ...