ruby

Why is :if not being recognised by ActiveRecord validations?

I have a problem where an :if clause within an ActiveRecord validation is not being honoured. My model has an ip_port attribute which I am validating as being present, numeric and within a certain range. I am trying to ensure that each condition only generates one error. I do not want the situation where an empty attribute results in th...

Extending Date class in ruby

Hi All, I want to extend Date class in ruby.Actually what I want to do is that add a method to Date class. Following is an example I want to add 'my_simple_method' method to Date class def my_simple_method puts 'this is from my_simple_method' end after adding this users should be able to call this method as date_obj = Date.parse...

How/what does the rails bin/rails file do.

Now, I've used Rails enough to know what the rails command does, but how it does it interests me. The bin/rails file (from github) is as follows: #!/usr/bin/env ruby begin require "rails/cli" rescue LoadError railties_path = File.expand_path('../../railties/lib', __FILE__) $:.unshift(railties_path) require "rails/cli" end As...

How to simulate Java-like annotations in Ruby?

How to simulate Java-like annotations in ruby? (We'll I have the answer, generalizing http://bens.me.uk/2009/java-style-annotations-in-ruby) ...

net/ssh in ruby(how to find)

my question is how do i fing net/ssh file in ruby . i am using 1.8.4 version of ruby ...

Could not find RubyGem rake (>= 0) (Gem::LoadError)

Hi, I'm having a hellava time with Rails these past two days. I was using the Rails 3 beta gem yesterday but went back to 2.3.8 and after cleaning the system gems and whatnot I'm just trying to run a simple rake task and I get this: Peleliu:haml jayfallon$ sudo rake install /Library/Ruby/Site/1.8/rubygems.rb:779:in report_activate_error...

Initiate Button click action using Watir Ruby library

Watir::Browser.default = "firefox" ie = Watir::Browser.start("http://cars.com") ie.select_list(:id, 'make_1').set('Chevrolet') ie.select_list(:id, 'model_1').set('Cobalt') ie.select_list(:id, 'pricehighnew').set('No Max') ie.select_list(:id, 'rdnew').set('30 miles') ie.text_field(:name, "zc").set "44109" ie.form(:method, ...

how to convert character encoding with ruby 1.9

i am currently having trouble with results from the amazon api. the service returns a string with unicode characters: Learn Objective\xE2\x80\x93C on the Mac (Learn Series) with ruby 1.9.1 the string could not even been processed: REXML::ParseException: #<Encoding::CompatibilityError: incompatible encoding regexp match (UTF-8 regexp w...

Is it possible to call a Module function from inside a class that is also in that module

In this Ruby code: Module M Class C < Struct.new(:param) def work M::helper(param) end end def helper(param) puts "hello #{param}" end end I get a "undefined method 'helper' for 'M:Module'" error when I try to run c = M::C.new("world") c.work but calling M::helper("world") directly from another class work...

Ruby xAuth support

I'm currently working in a service that has an API access through Oauth. I recently noted than Twitter will add support to xOauth, a lighter protocol intented for mobile and desktop access. It's possible to add xAuth support for my site or is only a Twitter technology? Thanks, Toño ...

Running command line commands within Ruby script

Is there a way to run command line commands through Ruby? I'm trying to create a small little Ruby program that would dial out and receive/send through command line programs like 'screen', 'rcsz', etc. It would be great if I could tie all this in with Ruby (MySQL backend, etc.) ...

Trying to parse a XML using Nokogiri with Ruby

I am new to programming so bear with me. I have an XML document that looks like this: File name: PRIDE1542.xml <ExperimentCollection version="2.1"> <Experiment> <ExperimentAccession>1015</ExperimentAccession> <Title>**Protein complexes in Saccharomyces cerevisiae (GPM06600002310)**</Title> <ShortLabel>GPM06600002310</ShortL...

Handling an XML file with Ruby and Nokogiri

Hello, I am new to programming so bear with me. I have many XML documents that look like this: File name: PRIDE_Exp_Complete_Ac_10094.xml.gz <ExperimentCollection version="2.1"> <Experiment> <ExperimentAccession>1015</ExperimentAccession> <Title>Protein complexes in Saccharomyces cerevisiae (GPM06600002310)</Title> <ShortL...

A Good Design Pattern for Ruby on Rails with Ajax for the following scenario?

I have two models A and B where updating B in some cases causes updates to A as well (done in model code). Now, in my UI, I want to display A and B in same page and can have their own operations (e.g. update some field in them). I don't want to reload the whole page on any update. My question is: I would like to put UI code for A and B...

Ruby: Round number down to nearest number based on arbitrary list of numbers

Say I have an array of integers: arr = [0,5,7,8,11,16] and I have another integer: n = 6 I need a function that rounds down to the nearest number from the array: foo(n) #=> 5 As you can see, the numbers do not have a fixed pattern. What's an elegant way to do this? Thanks ...

A web application as a logging frontend for Ruby

Hi, I was looking for a web application that hopefully catches log messages sent from Ruby programs and display them , much like the Chainsaw program (in integration with log4r). I tried to Google anything related but with no success so far. Does anybody have a suggestion ? Thanks in advance. ...

Can paperclip read photo geometry off an S3 bucket?

I would like to read the geometry of a photo off of my S3 container. When it's on my local, this works : def photo_geometry(style = :original) @geometry ||= {} @geometry[style] ||= Paperclip::Geometry.from_file photo.path(style) end But it doesn't seem to work when I switch my model over to S3.. Any recommendations? The bigger s...

jquery ajax is converting ruby objects array into has.

So I have this weird problem with jquery doing a ajax post with a ruby object. I have 2 options. 1. $('form_id'}.serialize(). I know this works. But my form simply has too many fields, and it is a little too inconvenient to manage them in the form 2. Second option, the rails controller is constructing a ruby object along the way as the f...

Why won't my Ubuntu server install Rails 2.3.8?

I have an older Ubuntu server with a Rails app running on version 2.3.5 that I'd like to move to version 2.3.8. The server doesn't seem to know that there is an update available, no matter how many times I run a "gem update" or "gem update --system" or "update_rubygems" root@server:~# gem install rails -v 2.3.8 ERROR: could not find ge...

Testing models with relationships and callbacks in Rails with RSpec and Factory_Girl

I'm still a working on learning RSpec so I'm sorry if completely overlooked something... I'm writing a test for a recipe that has many ingredients. The ingredients are actually added as a percent (with a total % column on the formulation) so I want to make sure that the total column updates after every save. So right now my RSpec test...