ruby

Normally should it be ok to install 1.86 with the one-click installer and then overwrite the install directory with 1.9? Or should I not have done that?

I used the one-click installer to install 1.86 a while back. I wanted to upgrade to 1.9 but since there's no one-click installer for 1.9 I just downloaded the 1.91 binary and overwrote my 1.86 install. Didn't work so well. I got errors all over the place afterwards. What's the proper way to upgrade (for a dummy, i.e. me)? The downloa...

Mongrel vs. WEBrick

What is the difference between Mongrel and WEBrick? Which one should I use? Why does Rails ship with both? ...

How do I automatically find a user's location?

I am currently working on a show listing website. I am going to display show information by location for the user sorted in a variety of different ways. I know I could ask the user where they are located when they first sign into the site, but I've seem to notice that many sites have this capability built-in to detect location automa...

How do I validate a date in rails?

I want to be able to validate a date in my model in ruby on rails. However, the day, month and year values are already converted into an incorrect date by the time they reach my model. For example, if I enter February 31st 2009 in my view, when I do Model.new(params[:model]) in my controller, it converts it to March 3rd 2009. Which my m...

Treetop SGF Parsing

I am currently trying to write a Treetop grammar to parse Simple Game Format files, and have it mostly working so far. However, there are a few questions that have come up. I am unsure how to actually access the structure Treetop generates after a parse. Is there a better way to handle capturing all characters than my chars rule? Ther...

How to do a safe join pathname in ruby?

My development environment is in Windows, and my production of rails is in Linux. There are possibility that VirtualHost will be use. Assume that one finename need to call in /public folder with File.open('/tmp/abc.txt', 'r'). but in my Windows it should be "C:\tmp\abc.txt". How can i do a right join path with two difference environm...

How to access instance variables from one class while inside another class

I'm really new to Ruby. And by new - less than 16 hours, but my boss gave me some Ruby code to add to. However, I found it was one giant file and not modular at all, so I decided to clean it up. Now that I've broken it up into several files/classes (generally speaking, 1 class per file,) I'm having problems piecing it together for it to ...

Limit fetch size of Net::HTTP.request_get

I want to fetch some content from a webserver using Net:HTTP, like this: url = URI.parse('http://www.example.com/index.html') res = Net::HTTP.start(url.host, url.port) {|http| http.get('/index.html') } puts res.body But I need to limit the get to the first 5kb to reduce the network traffic. How do I do this? ...

xpath expression for regex-like matching?

I want to search div id in an html doc with certain pattern. I want to match this pattern in regex: foo_([[:digit:]]{1.8}) using xpath. What is the xpath equivalent for the above pattern? I'm stuck with //div[@id="foo_ and then what? If someone could continue a legal expression for it. EDIT Sorry, I think I have to elaborate more...

decode base64 with dollar sign in ruby 1.8.5

Hello, I have base64-encoded string (with two dollar signs, so it's not a common base64 string) The problem: Base64.decode64 (or .unpack("m")) decodes it just fine on my local machine(ruby 1.8.6), but with ruby 1.8.5 (the version used by Heroku) it doesn't work Any ideas ? edit: I have : $$YTo1OntzOjM6Im1pZCI7czo3OiI3MTE5Njg3IjtzOj...

Creating Plain .rb Files with Aptana RadRails

I have just bought a MacBook for some ruby development and like the look of Aptana Studio as a really nice IDE. The question I have, however, is that I want to know (before getting too deep into it, and potentially wasting time) is can I create plain old .rb files without the rails framework attached? Also, can I execute the ruby file ...

Vanishing Ruby Gems

I'm using Ubuntu 8.10 and I installed Ruby and Ruby on Rails following the directions on this site. The exact directions I followed are no longer there as it appears the rubyonrails.org wiki has changed recently. But I installed it the long way. Installed Ruby, then Gems, then installed Rails using "gem install rails". I haven't really m...

genrating WSDL in Ruby

Hi I starting to work with ruby and soap and had some questions : how do I generate a WSDL file for the service I created ? will it be compatible with an .NET client ? Thanks, Gady begin class MyServer < SOAP::RPC::StandaloneServer # Handler methods def add(a, b) return a + b end def div(a, b...

How to use haml with heroku ?

Hello I try to get haml working without the gem with sinatra (Heroku doesn't allow gem install, as far as I know) What I've done so far: clone the haml git repo inside my project add : require 'haml/lib/haml.rb' to my sinatra main file the following works: get '/test' do Haml::Engine.new('%p test').render end but the following...

The string count() method

Hi, Busy learning Ruby... the documentation have an example: "hello world".count("lo", "o") that return 2 how does that return 2? In my example I've: puts "Lennie".count("Le", "ie") that return 2. How does count work in this regard? ...

Ruby headscratcher - instance variable isn't outputted

I'm probably doing something stupid but I can't figure out what it is. The output I'm seeing from this program is foo test What I'm expecting to see is foo abc test Does anyone see anything obviously wrong here? class Foo def initialize(l) @label = l end def label @label end def abc @abc en...

Locomotive slowing to a crawl

I have recently been building very small and simple apps using Locomotive 2.0.8. Until now it has been the ideal solution, but recently the application has slowed to absolute crawl. It takes literally 10 minutes to boot up, 5 minutes to add an existing or new project - and often these creations don't even work correctly. I can't imagine ...

Namespaced models in Rails: What's the state of the union?

Hi all, Since the beginning, Rails has had issues with namespaced models. As time went on, pretty much everybody gave up on using it. Myself included. With Rails 2.3 out, I'd like an update on the situation. Specifics questions I have in mind are: first off, is it good to go? table naming, what rule to follow? associations, how to d...

AJAX pattern in Rails for submitting small chunks of data

I have a web page with lots of small images on it. In a typical scenario user clicks on image and expects it to change with a new image. Requirements: When user clicks on image, it should be immediately known to a controller in an Ajax way. Some strings should be passed to a controller when user clicks on image. Controller does its...

How do you loop through a string in Ruby?

Pretty simple question from a first-time Ruby programmer. How do you loop through a slab of text in Ruby? Everytime a newline is met, I want to re-start the inner-loop. def parse(input) ... end ...