ruby

How do you implement a function which returns the URL of last visited page

Hello, I want to store the current URL in a session variable to reference the previous visited page. If I store every URL (via a before_filter on ApplicationController), also actions which end in a redirect (create, update, etc) are considered as last visited page. Is there a way to tell Rails only to execute a function if a template ...

Polymorphic Models in Ruby on Rails?

For a project I'm working on, the store has two types of products - a real product and a group of products. For this discussion, let's call them "1 T shirt" and "a box of T shirts". For one t-shirt, I need to store the normal attributes - price, sku, size, color, description, etc. For the box of t-shirts I need to have a price, sku,...

Ruby Soap4R Web Service, .NET Consumer

Does anyone know how to generate WSDL from a Web Service in Ruby using Soap4R. I have a fairly simple Web Service (SOAP::RPC::StandaloneServer) and would like to consume from .NET . Thanks ...

How do I write a custom validation method with parameters for my ActiveRecord model?

In my model I have: validate :my_custom_validation def my_custom_validation errors.add_to_base("error message") if condition.exists? end I would like to add some parameters to mycustomer vaildation like so: validate :my_custom_validation, :parameter1 => x, :parameter2 => y How do I write the mycustomval...

Javascript with embedded ruby - How to make sure the string does not break?

I have this line in a javascript block in a page: res = foo('<%= @ruby_var %>'); What is the best way to handle the case where @ruby_var has a single-quote in it? Else it will break the js code. ...

How can I get source and variable values in ruby tracebacks?

Here's the last few frames of a typical Ruby on Rails traceback: And here are the last few frames of a typical Nevow traceback in Python: It's not just the web environment either, you can make similar comparisons between ipython and irb. How can I get more of these sorts of details in Ruby? ...

Building Ruby on Windows XP

Has anyone out there got a good set of instructions for building/compiling Ruby from source of windows XP ? ...

How do I test that a Rails Helper defines a method?

I am creating a Rails plugin and it is dynamically adding a method to a Helper. I just want to ensure that the method is added. How can I see if the Helper responds to the method name? ...

Uniq by object attribute in Ruby

What's the most elegant way to select out objects in an array that are unique with respect to one or more attributes? These objects are stored in ActiveRecord so using AR's methods would be fine too. ...

Not getting emails from ExceptionNotifier

I followed this tutorial on configuring the Rails plugin ExceptionNotifier. I know that I have ActionMailer configured correctly because I am getting mail from other forms. I even have local_addresses.clear set so that it should be delivering mail no matter what. I am using Apache with a mongrel_cluster running in the backend. What am...

Regular expression to match only the first file in a RAR file set

To see what file to invoke the unrar command on, one needs to determine which file is the first in the file set. Here are some sample file names, of which - naturally - only the first group should be matched: yes.rar yes.part1.rar yes.part01.rar yes.part001.rar no.part2.rar no.part02.rar no.part002.rar no.part011.rar One (limited) w...

Why should I use RSpec or shoulda with Rails?

I am setting up a rails app and I just finished making some unit tests and my friend said that apparently fixtures are no longer cool and people are now using RSpec or shoulda. I was wondering what the actual benefits are to use these other toolkits. Any information at all is appreciated. -fREW ...

Mod_rails and mongrel running on the same server?

I'm currently running mongrel clusters with monit watching over them for 8 Rails applications on one server. I'd like to move 7 of these applications to mod_rails, with one remaining on mongrel. The 7 smaller applications are low-volume, while the one I'd like to remain on mongrel is a high volume, app. As I understand it, this would b...

interval rails caching

I need to cache a single page. I've used ActionController's caches_page for this. But now, I'd like to expire AND regenerate it once in every 10 minutes. What are my options? later: I'd like to not use any external tools for this, like cron. The important point is interval-based expiry of the cache. ...

Best way to add tests to an existing Rails project?

I have a Rails project which I neglected to build tests for (for shame!) and the code base has gotten pretty large. A friend of mine said that RSpec was a pain to use unless you use it from the beginning. Is this true? What would make him say that? So, considering the available tests suites and the fact that the code base is already the...

Ruby - Ensure Syslog Gets Closed

Is it absolutely critical that I always close Syslog when I'm done using it? Is there a huge negative impact from not doing so? If it turns out that I definitely need to, what's a good way to do it? I'm opening Syslog in my class constructor and I don't see a way to do class destructors in Ruby, and currently have something resembling t...

What is the best way to return multiple tags from a Rails Helper?

I want to create a hidden field and create a link in one helper and then output both to my erb. <%= my_cool_helper "something", form %> Should out put the results of link_to "something", a_path form.hidden_field "something".tableize, :value => "something" What would the definition of the helper look like? The details of what link_t...

Combining Scriptaculous and JQuery in a Rails application

I've got the following situation A rails application that makes use of rjs / Scriptaculous to offer AJAX functionality Lot of nice javascript written using JQuery (for a separate application) I want to combine the two and use my JQuery based functionality in my Rails application, but I'm worried about JQuery and Scriptaculous clashin...

How to read a barcode from an image

I'm seeking a library, technique or advice on how to read an EAN-13 barcode from an image (including ISBN,and ISSN encodings). The image would come from a mobile phone or webcam, so resolution may be quite poor and not well aligned. I'm specifically interested in something that could be used from ruby on rails, but answers for other lan...

Looking for tools to analyze email data

I made a write-up about how to analyze your gmail account data with ruby. Then on SlashDot, someone told me about mail-trends. Does anyone have other tools to suggest ? ...