ruby

Writing out a custom file as a response from a rails controller action

So I want to dynamically generate a MIDI file on a web request.Coming from the Java world, I expected something to the tune of class MidisController < ApplicationController before_filter :set_content_type def set_content_type @headers["Content-Type"] = "audio/midi; charset=utf-8" end def show midi_data = get_midi_da...

Installing ruby gems fails when attempting to build native

So I decided that I was going to give Ruby (first 1.9.1, then 1.8.7) a try and I wanted to get the basic tools installed before I attempted to do too much. I have begun to install some gems, and I have run into some issues when I attempt to install one which builds native code on windows 7. I was attempting to install the ruby debugge...

Package Sinatra app into a single JAR file?

Hi everyone, I've an apparently (silly) simple question: With JRuby is it possible to deploy a single file Sinatra application? I mean: I've my Sinatra app with all needed gems exploded into some ./vendor/lib directory and I'd like to deploy the whole app as a single jar file to run on a deployment machine: $ java jar my_app.jar whe...

how to increment a counter written into a file in ruby

I am making a count of how many times a module fails into a file. so whenever it fails, i open the file, increment the number in the file and close it. How i can i do it with opening the file just once instead of opening it twice once for reading and another of writing. Thanks ...

Is there something like Java Quartz in ruby?

The is a library like Quartz in Java for ruby? ...

Relationships of model

Hi! How can I get all relationships for model. IE, I've got User model: class User < AR::Base has_many :messages, :foreign_key => 'author' has_many :posts belongs_to :role end So how can I know which relationships User model has got? And foreign_keys if they are presented. ...

How do I install the Ruby ri documentation?

I've recently installed Ruby 1.9.1 on Windows 7, and apparently it doesn't come with the standard ri documentation. So when I do 'ri Array', I get: C:>ri Array Nothing known about Array Is there a way I can install this documentation so that the above works? Thanks, Grant ...

require a file again if its changed

I've written a gem that looks in config/ for a config file, this bit works fine and its not throwing any problems but if the user changes any config they have to stop the program and start it again before my gem loads the new config, which would require them to restart a rails app every change, which isnt ideal. is there a way to "re-re...

ruby - simplify string multiply concatenation

s is a string, This seems very long-winded - how can i simplify this? : if x === 2 z = s elsif x === 3 z = s+s elsif x === 4 z = s+s+s elsif x === 5 z = s+s+s+s elsif x === 6 z = s+s+s+s+s Thanks ...

Geokit: can it support utf8 results (or suggestions) ?

Well the problem is that GEOKIT (a ruby gem to work with maps) when using it with Google Map for example returns results in ascii, like: Svobody prosp 34, Moskva, Rossia Svobody prosp 35, Moskva, Rossia Svobody prosp 36, Moskva, Rossia This happens if either I type query in utf8 or ascii. But I want it to return utf8 results like her...

Encoding problems with hpricot

I am getting the following encoding error when trying to scrap web pages with hpricot in ruby 1.9: Encoding::CompatibilityError: incompatible character encodings: ASCII-8BIT and UTF-8 I can reproduce the error by doing the following: ska:~ sam$ rvm 1.9.2@hpricot ska:~ sam$ ruby -v ruby 1.9.2dev (2010-05-31 revision 28117) [x86_64-dar...

How to use german umlaute in rails3 routes

Hi folks, really big problem example request http://localhost:3000/freund/in/münchen my first route in routes.rb match ':category/in/:city' => 'home#index', :constraints => {:city => /(berlin|hamburg|münchen)/ } and I get the error Routing Error No route matches "/freund/in/m%C3%BCnchen" what can I do? I postet everywhere :( ...

Please explain this joke about Ruby

From How to Shoot Yourself in the Foot in Any Programming Language: Ruby. Your foot is ready to be shot in roughly five minutes, but you just can’t find anywhere to shoot it. I don't have experience with Ruby. I guess the first part states that development is fast. What's the meaning of "just can't find where to shoot it" part? ...

How to use RubyTorrent? (or other gems)

I was reading the book Ruby Cookbook by O'Reilly, and it has a section on RubyTorrent But if I do the following on Win 7: > gem install rubytorrent > irb irb(main):001:0> require 'rubytorrent' LoadError: no such file to load -- rubytorrent from (irb):6:in `require' from (irb):6 I looked and found that C:\Ruby\lib\ruby...

Unknown gem rack >= 0 error

I keep getting this error message when trying to uninstall rack... $ sudo gem uninstall rack ERROR: While executing gem ... (Gem::InstallError) Unknown gem rack >= 0 When I do gem list -l... *** LOCAL GEMS*** rack (1.2.1, 1.1.0, 1.0.1) Same error with gem uninstall rack (no sudo) I've also tried gem uninstall rack --version ...

Virtual attributes in rails model

In my controller I'm calling @hour.shopper.add_product within a for loop. My model looks like: class Shopper < ActiveRecord::Base attr_accessor :quantity def add_product if self.quantity.nil? || \ self.quantity == 0 self.quantity = 1 else self.quantity += 1 end self.save end end When ...

Problem with rails scaffolding (windows + netbeans + sqlite3)

I'm experimenting with Ruby on Rails. I'm using NetBeans on Windows 7. I am trying to follow this tutorial, but instead of using MySQL, I'd like to use SQLite3. Here is my database.yml file: # SQLite version 3.x # gem install sqlite3-ruby (not necessary on OS X Leopard) development: adapter: sqlite3 database: db/development.sqlit...

How to split an array in ruby?

Given an array arr = [['a', '1'], ['b','2'], ['c', '3']] Whats the best way to split it into 2 arrays eg: first = ['a','b','c'] and second = ['1', '2', '3'] ..can i do this via a collect? ...

Ruby background process communication

How can I communicate with a process using anonymous pipes in Ruby? The process in question is supposed to stay there and listen for commands from stdin. I'd also like to read it's output, which is separated by "\r\n". Using Open3 from the standard library: @stdin, @stdout, @stderr, @thr = Open3.popen3(cmd) The problem with this is ...

Rack Request Log

Why Is there a reason Rack's request log by default outputs to stderr? If i'm not mistaken, the request log is Rack::CommonLogger which according to the RDoc: forwards every request to an app given, and logs a line in the Apache common log format to the logger, or rack.errors by default. Doesn't it make more sense to have an acces...