ruby

Ruby on Rails, form_remote_tag, and Google Maps API

I am trying to add Google Maps to my page using YM4R/GM. As a regular submit using form_tag everything works, so I know I didn't mess that part up. But using form_remote_tag I end up with nothing inside my update div. I tested with rendering text so the right method is being executed and YM4R/GM is returning the Google Maps KML. But t...

How to Get Results From a Background Process

I am designing a Ruby on Rails application that requests XML feeds, reads them in, and parses them into objects to be used in views. Since the request for the XML feed and subsequent receipt of it can take several seconds from some sources to complete I need a way to offload these tasks from my front-line application tier. I do not want ...

Opening a WIKI URL with a comma using `open-uri`

I am running in to OpenURI::HTTPError: 403 Forbidden error when I try to open a URL with a comma (OR other special characters like .). I am able to open the same url in a browser. require 'open-uri' url = "http://en.wikipedia.org/wiki/Thor_Industries,_Inc." f = open(url) # throws OpenURI::HTTPError: 403 Forbidden error How do I escape...

Windows Equivalent of System Configuration Directory

I am developing a CLI application in Ruby, and I'd like to allow configuration in Unix via the standard config file cascade of /etc/appnamerc, ~/.appnamerc. However, the application is also meant to be run in a Windows environment, and I'm unsure of where one would put a file like /etc/appnamerc (C:\windows\system32\etc\drivers does not ...

ruby string concatenation (I think?)

I'm just starting with "The Well-Grounded Rubyist", and they gave the following example: print "Hello. Please enter a Celsius value: " print "The Fahrenheit equivalent is ", gets.to_i * 9 / 5 + 32, ".\n" In particular, I'm looking at line 2, where they seem to be using commas for string concatenation. I assume the + symbol isn't being...

observer does not work in IE

In my ruby on rails app I am trying to use a Prototype Form.Element.Observer to run a count of the characters in a message. This works fine on Firefox/Safari/Chrome, but not on IE. On IE the observer simply does not fire. Is there a fix or a different way of doing this? My ruby tag looks like this: <%= countdown_field('txtmsg[memo]'...

Alphabetize Arabic and Japanese text that is in Unicode?

Does anyone have any code for alphabetizing Arabic and Japanese text that is in Unicode? If the code was in ruby that would be great. ...

Running a loop (such as one for a mock webserver) within a thread

I'm trying to run a mock webserver within a thread within a class. I've tried passing the class' @server property to the thread block but as soon as I try to do server.accept the thread stops. Is there some way to make this work? I want to basically be able to run a webserver off of this script while still taking user input via stdin.get...

Changing the `Proc` binding during invocation

Is it possible to change the binding of a procedure during invocation time? class AllValidator def age_validator Proc.new {|value| self.age > value } end end class Bar attr_accessor :age def doSomething validator = AllValidator.new.age_validator validator.call(25) # How to pass self as the binding? end end In th...

How to convert a string to a constant in Ruby ?

how to convert the string "User" to User ? ...

ROR: Localised Message String Variable Substitution

I am trying to work out the best way to replace multiple variables/placeholders within localized message string in my ruby on rails application. When replacing a single placeholder I have used the satisfactory: In en.yml: url_borked: "The URL: $url could not be loaded." In view: t(:url_borked)["$url"] = request.url But this is ...

How to use variable arguments with ruby's OptionParser

I don't know ruby very well, but I'm trying to add some functionality to this script a co-worker wrote. Basically right now it takes a few flags and standard in as input, and it uses OptionParser to parse the flags. I want to use OptionParser to parse a selection of command line arguments similar to those of cat. So I guess my questio...

How to get instance_of to work with ActiveRecord objects in RoR?

Today I ran into an issue using RoR to stub calls to AR objects. I thought that I'd be able to do something along the lines of : stub.instance_of(BankAccount).save_to_other_spot { true } However when I tried this method it didn't seem to stub the method at all and it would end up running the original method I was trying to stub. I con...

How to enable SSL for a standalone Sinatra app?

I want to write a quick server app in Sinatra. It has to be self-contained (i.e. not use apache/nginx/passenger) but also has to support SSL. Is there an easy way to enable SSL support for Sinatra (using WEBRick for example)? ...

Ruby and WIN32OLE: Cannot call WIN32OLE_TYPE methods (Type Libraries)

Okay, so I'm doing some good OLE' (sorry) automation with ruby and I ran into a weird problem. I'm trying to extract some data from a Type Library. This works in VB: Dim c As New TControlsLib.LangCombo Dim l As TControlsLib.Language Dim converter As New TControlsLib.LcidConverter c.AddAllSystemLanguages mtAllKnownLanguages, True For Eac...

Discussion with a sub-process, using Ruby with IO and threading

Hi everyone, I am trying to use IO.popen in order to put (with .puts method) and to get (with .gets method) messages from a process to its sub-process. I am not very experimented and I have a question about. Having the following code, I have an error because it is not possible to write in a closed stream. class Interface def initia...

Error while updating a record using Formtastic in HAML templates

I am using formatastic in a HAML form. - semantic_form_for @company do |f| - f.inputs do = f.input :description = f.input :type = f.input :industry = f.input :hq = f.input :products = f.input :subsidiaries = f.input :employees = f.input :revenue = f.input :net_income = f.buttons When ...

Drawing the line between the model and the Controller

I'm building this restful application using RoR, and am finding it a bit difficult to draw a line between things that should go on the model, and things that should go on the controller. As an example, I have 7 methods on my controller (the ones that make it restful i.e. index(), show(), create(), update()...), and often find that it's ...

Merging HTML files

I want to merge one HTML file into another. Not just include it, but merge. Example master.html: <!DOCTYPE html> <html> <head> <title>My cat</title> </head> <body> <h1>My cat is awesome!</h1> </body> </html> _index.html: <!DOCTYPE html> <html> <body> <p><img src="cat.jpg"/></p> </body> </html> Now I merge ...

ruby gems on xampp help

i have googled in the last 3 hours but i can't seem to find any precise info. All i know is PHP, i don't know anything about ruby or ror, I need to run this open source project management app http://www.redmine.org/wiki/redmine/RedmineInstall on my xampp, but can anyone tell me how to do things properly i mean install stuff with my xampp...