ruby

Ruby on Rails: how do I catch ActiveRecord::Rollback?

In my controller, I have code that looks like the following: @mymodel.transaction do for a in arr @mymodel.some_method(a) end end in @mymodel#some_method I could throw an ActiveRecord::Rollback exception which in the db does what it needs to do, however I then simply get an HTTP 500 and no way to catch the...

Help with capturing with regexp

I have this list: foo chef.rb baz bar cucumber.rb bar baz gem.rb foo I want to capture all the names without .rb. My current regexp looks like this: /([^\s](?:.)*?.(?:rb))/i But it captures the .rb too. How do I capture just the base name? Thanks. ...

Initialize cucumber folder structure?

Is there an easy way to initialize a cucumber folder structure like rails generators? ...

Case selection in Ruby

Here is my code: case input when "quit" || "exit" break end Only "quit" works here and not "exit". How could I have "exit" work too without having to have a new "when" line? ...

Python (or maybe JavaScript / Ruby): open source projects that will give me a (bit) of hand-holding

Ive been roaming around the interwebs looking for my first open-source project to contribute to - and most cool ones seem to be one-man bands on github, which I could fork - but wouldnt quite provide the code review etc. i think i want, so i can improve my python abilities. Web.py, flask, celery, twisted etc look interesting - so far on...

Ruby on Rails. A custom message in a custom validator method

Hi. I want to have an ability to set a custom message in a model validator method to notify a user about incorrect input data. Firstly, I set a custom validator class where I redefine the validate_each method in that way as it recommended in rails' documentation: # app/models/user.rb # a custom validator class class IsNotReservedVa...

How to delete document from CouchDB using CouchPotato?

I have problems finding documentation on how to delete a document from CouchDB using CouchPotato. As fare as I know I have to set the property _deleted = true. When I want to get documents that is not deleted, I have tried to add a condition to my class like this: view :item, :key => [:userid, :date], :conditions => 'doc._deleted === ni...

Ruby MongoDB- how to sort records based on datetime?

Hi all: I must have done it in a wrong way: the records printed out are out of order, even though they are inserted into db one at a time. Here is the code: get '/' do db = Mongo::Connection.new("localhost", 27017).db("testdb") @notes = db.collection('notes') @notelist = Set.new() @notes.find().each{|record| @notelist.add(recor...

Jekyll vs RefineryCMS?

I know many Ruby users are using Jekyll but I wonder what the benefits that will bring over RefineryCMS? Could someone highlights the differences and pros/cons for each. ...

How can I pipe data to a process started via Net::SSH on stdin?

I'm generating a data feed on the local machine, that I want to pipe into a remote process via Net::SSH. Something like echo foosball | sed 's/foo/bar/g' Just that the echo foosball part would be the data feed on the local machine. What I'm NOT looking for is: data = "foosball" ssh.exec!("echo #{data} | sed 's/foo/bar/g'") I real...

Ruby on Rails: what's the minimum I need to load if I want to use ActiveRecord in a maintenance script

I created a top level directory called 'maintenance' in my Ruby on Rails application. There's mostly scripts there that I use for my own cleanup/project maintenance. I want to be able to load my models and activerecord so I can query them in my script. What do I have to load at the beginning of the script to get it to properly know my en...

How do I create a ruby app that I can run commands on

I am building a little tool in ruby for creating directories and files based on commands that I issue it from the command line. I would like for this to work on Mac, Windows, and Linux. I am of course new to ruby and I know how to right a simple script and call it to run from the command line. What I would like to do is be able to navig...

Installing Ruby 1.9.2 through RVM fails.

Hi everyone, I've installed rvm following the official guide on rvm. I installed Ruby 1.8.7 with rvm install 1.8.7 and then set it as default with rvm 1.8.7 --default. Now I tried to install 1.9.2 with rvm install 1.9.2(also tried rvm install 1.9.2-head). Everything goes fine until I get to the "ruby-1.9.2-head - #installing-part. The...

Can you use Ruby to develop a touchscreen supported application?

What api's do you use to develop a touchscreen point of system in Ruby? ...

[Ruby] How to access the parent collection in a each closure?

I'm looking from something that to replace the *parent*. %w[apple apples].each do |w| next if *parent*.includes? w + "s" puts w end # output: apples ...

Ruby on Rails: alias_method_chain, what exactly does it do?

I've tried reading through various blog posts that attempt to explain alias_method_chain and the reasons to use it and not use it. In particular, I took heed to: http://weblog.rubyonrails.org/2006/4/26/new-in-rails-module-alias_method_chain and http://yehudakatz.com/2009/03/06/alias_method_chain-in-models/ I still do not see any prac...

Why is this recursion NOT infinite?

My friends and I are working on some basic Ruby exercises to get a feel for the language, and we've run into an interesting behavior that we're yet unable to understand. Basically, we're creating a tree data type where there's just one class, node, which contains exactly one value and an array of zero or more nodes. We're using rspec's...

Explain Ruby Commify large integer method

I found this snippet online and the purpose is to commify any number including numbers with decimals ... 99999999 => 99,999,999. I can see that it uses regex but I am confused by "$1.reverse, $2" def commify(n) n.to_s =~ /([^\.]*)(\..*)?/ int, dec = $1.reverse, $2 ? $2 : "" while int.gsub!(/(,|\.|^)(\d{3})(\d)/, '\1\2,\3') end ...

How to make Sinatra work over HTTPS/SSL?

As the title says... Google doesn't give anything useful concerning this. How do I set up and configure https/ssl for Sinatra apps? How to create a https route? etc. I have never used https for my apps before and have no experience tweaking Rack/whatever, so I appreciate detailed answers... ...

How to update Ruby to 1.9.x on Mac?

I have created a new user account on my mac and I am trying to update to the current version of ruby on it (1.9.2) from the snow leopard default of 1.8.7. Can somebody point me to tutorial or explain the best method to update Ruby on my mac from 1.8 to 1.9.2? Thanks ...