ruby

Storing Objects in a Session in Rails

Hello, I have always been taught that storing objects in a session was a bad idea. Instead IDs should be stored that retrieve the record when needed. However, I have an application that I wonder is an exception to this rule. I'm building a flashcard application, and the words being quizzed are in a table in the database whose schema ...

Sub-classing Fixnum in ruby

So I understand you aren't supposed to to directly subclass Fixnum, Float or Integer, as they don't have a #new method. Using DelegateClass seems to work though, but is it the best way? Anyone know what the reason behind these classes not having #new is? I need a class which behaves like a Fixnum, but has some extra methods, and I'd lik...

CopyFileExW in Ruby

Does anyone have a code sample that shows how to use the Win32 function CopyFileExW in ruby? The difficulty i am having is declaring the 'ProgressRoutine' call back function correctly without getting a segfault. I can use CopyFileW without issue, but CopyFileExW is causing grief. require 'windows/error' require 'windows/wide_string' re...

Is Rails enviroment the prerequisite for cruisecontrol.rb

I have no rails enviroment but I want to use cruisecontrol.rb as my Continous Integration enviroment. After following the instrcution from http://cruisecontrolrb.thoughtworks.com/documentation/getting_started and then ./cruise start I got the error here: (sorry, but the formatter is better than posting it here directly) http://pas...

serve my text from the filesystem instead of a database?

I am working on a content management application in which the data being stored on the database is extremely generic. In this particular instance a container has many resources and those resources map to some kind of digital asset, whether that be a picture, a movie, an uploaded file or even plain text. I have been arguing with a colle...

Example of Basecamp API ruby wrapper usage

I've set up a new Rails 2.3.2 app and added the Basecamp API ruby wrapper to my /lib directory from here: http://developer.37signals.com/basecamp/basecamp.rb In my application_controller.rb I have created the following method to enable calls to Basecamp: def basecamp_connect Basecamp.establish_connection!('xxxxxx', 'xxxxxx', 'xxxxx...

Writing an ActiveRecord plugin for Rails

I'm writing my first rails plugin and could use a little help. In a very simplified way, I'd like to do allow the developer to specify a value which I can count through a rake task. I'm thinking of something like this... class User < ActiveRecord::Base monitor "Users", count monitor "Active Users", count("activated_at != NULL")...

Ruby to Groovy

I have a framework written in Ruby that needs to be converted into Groovy. It does not use anything outside of core ruby, but a lot of meta programming. Are all the same basic features supported by Groovy and is the changeover complicated? ...

Rails Many to Many relationship issue

I have the following models: class Person < ActiveRecord::Base has_many :accounts, :through => :account_holders has_many :account_holders end class AccountHolder < ActiveRecord::Base belongs_to :account belongs_to :people end class Account < ActiveRecord::Base has_many :people, :through => :account_holders has_many :acco...

How to store a file (xml) requested by http into an object?

I want to get a xml file, which I can request by an http request into an object. I'm looking for something similar to this (in a controller): @ticket = request "http://example.com?ticketid=1234" http://tickets.com?ticketid=1234 returns an XML (tickets.com is not the site the app is running on). I then want to parse @ticket, to get th...

How do I find out if my html document is well formed in ruby

Every html document is an xml document. In the current project there are a lot of html tags which are not properly closed. This is a ruby on rails application. I want to put an after filter which will parse the whole html output and will raise an error if the parsing detects that it is not a well-formed document. In this case well-forme...

ActiveRecord dependency with Ruby, Rails, Cucumber, & RSpec

We are writing a Rails application that is using CouchDB as its data store. We're BDD/TDD'ing with RSpec and Cucumber, which is using WebRat for webpage testing I'm trying to remove ActiveRecord as one of the resources that is being loaded by rails but its causing the cucumber tests to fail. I've removed all references that I can find...

Sinatra / Ruby Server Push

What is the best way to push data from a server written in Sinatra (ruby) to a client? Think similar to a chat room, but without ajax polling every 2500ms. I know of Juggernaut in rails, but was curious about Sinatra. Thanks, -Tom ...

Why is Ruby more suitable for Rails than Python?

Python and Ruby are usually considered to be close cousins (though with quite different historical baggage) with similar expressiveness and power. But some have argued that the immense success of the Rails framework really has a great deal to do with the language it is built on: Ruby itself. So why would Ruby be more suitable for such a ...

How do I get the response returned from Rack in a Cucumber step?

I have a Cucumber step for my Rails application: Then /^I should be redirected to the sign in page$/ do assert_equal 302, @response.status end But that @response object is the one returned by my Controller, and it's the Rack middleware that sets the status to what I expect it to be. How can I get at the response as returned from th...

Ruby types of collections in ActiveRecord

If I have an object with a collection of child objects in ActiveRecord, i.e. class Foo < ActiveRecord::Base has_many :bars, ... end and I attempt to run Array's find method against that collection: foo_instance.bars.find { ... } I receive: ActiveRecord::RecordNotFound: Couldn't find Bar without an ID I assume this is because A...

Rails "render :text => proc" in 2.2.2 versus 2.3.2

I'm experiencing something that I can't explain with Rails 2.3.2. I've created a new app, with one controller and one action to try narrowing this down. My entire controller is as follows. class LinesController < ApplicationController def show respond_to do |format| format.html { render :text => proc {|response, output| ...

What can JavaScript learn from Ruby?

The ECMAScript working group has started working on the next edition of the language. What can they learn from Ruby? ...

How to Set Timeout for Ruby ODBC Driver for SQL Server?

Hello, I would like to know how to explicitly set a timeout for the Ruby DBI ODBC driver, when connecting to SQL Server. I would like long running queries to simply timeout and cancel themselves, saving further server resources and Rails processes. This was happening while we were using the ADO based Ruby driver, but now that we've sw...

Ruby on Rails method to calculate percentiles - can it be refactored?

I have written a method to calculate a given percentile for a set of numbers for use in an application I am building. Typically the user needs to know the 25th percentile of a given set of numbers and the 75th percentile. My method is as follows: def calculate_percentile(array,percentile) #get number of items in array return nil i...