ruby-on-rails

Ruby Time Calculations

I am trying to determine the duration of elapsed time minus any interruptions. The method below seems inefficient and silly is there a better method? The user specifies an end_time and a start_time are and records any interruptions as an integer representing minutes. def duration ((end_time - start_time).seconds - interrupt.minutes) ...

How to run a single shoulda context test in ruby Test::Unit framework

I can typically test a regular Test::Unit method using the following commandline syntax for a method "delete_user_test": ruby functional/user_controller_test.rb -n delete_user_test Now when I'm using the shoulda plugin with Test::Unit I try to use the same technique as follows: ... context "Deleting a User" do should "remove user ...

Conditions with Bind Variables and Optional Parameters

Let's say I have a form where users can search for people whose name starts with a particular name string, for example, "Mi" would find "Mike" and "Miguel". I would probably create a find statement like so: find(:all, :conditions => ['name LIKE ?', "#{name}%"]) Let's say the form also has two optional fields, hair_color and eye_color ...

Rails functional test file access

I need to access a file in a Rails functional test in test/functional/main_controller_test.rb. If I mention the file within "", and the included file is placed in test/ directory, I can run the test using: $ cd test $ ruby functional/main_controller_test.rb But, I get a cannot find file error, when I use it from the top-level Rails p...

Pass additional parameters to a controller

I have this link to create a new page: "new" %> The code called in the controller is this: def new @page = Page.new @visuals = Visual.find(:all) end I would like to pass an additional parameter to pre-set a field in the form, something like this: "new/parent_id/2" %> and in the controller def new @page = Page.new ...

How to use ActiveRecord in a ruby script outside Rails?

I have a small ruby script in which I'd like to use ActiveRecord to easily access a database model. What is the best way to do it? ...

Tools for Ruby on Rails projects in Perforce

Hi, we are using Perforce for source configuration management and I have just started to hack some small stuff in Ruby on Rails. As Perforce follows the "check-out before modify" paradigm, and RoR expects to have all files writable for the various script/ stuff, do you know/use any helpers to make RoR work together with Perforce? I know ...

Calling Lisp from Ruby/Rails?

How might you call a Lisp program from a Rails application?... For example, allow the end user to enter a block of text in the Rails web app, have the text processed by the Lisp program and return results to the Rails app? ...

Rails Migrations: Check Existence and Keep Going?

I was doing this kind of thing in my migrations: add_column :statuses, :hold_reason, :string rescue puts "column already added" but it turns out that, while this works for SQLite, it does not work for PostgreSQL. It seems like if the add_column blows up, even if the Exception is caught, the transaction is dead and so the Migration can...

default_scope with :joins and :select

I tried to define a default_scope in the following way: default_scope :joins => :product, :select => "catalog_products.*, products.*" What I'm getting from Rails though is this: SELECT catalog_products.* FROM `catalog_products` INNER JOIN `products` ON `products`.id = `catalog_products`.product_id When I define it as a named_scope...

UnixODBC driver support in OSX?

I'm working on a Rails application which I've set up locally on my OSX Machine. However, the app, which typically runs on a Linux box, connects to a proprietary database via unixODBC. The database manufacturer only provides drivers for Linux and Windows. I did some searching around but couldn't figure out what the state of unixODBC is...

acts_as_audited. How can I add a "comment" column

Hi guys, I am using the acts_as_audited gem with my application. (Excellent gem to keep track of changes of model objects) I have been asked to support associating a text comment with each Audit record (similar functionality to svn commit). And I am stumped on how to accomplish this. For example. Lets say I have an address form, and...

What's the best (and cheapest) Rails hosting provider for a prototype application?

I know the question on what the best Rails host has been asked and discussed before, but I'm looking more for advice with my specific scenario. I have a SyncML server that requires a minimum of 512MB RAM that I want to hook up to a Ruby on Rails front end. I'm going to be using a Linux environment to serve these. What I'm putting toge...

Ruby GIS - Converting NAD83 to WGS84

I'm in the processing of developing a GIS component for our product and I have the need to convert NAD83 to WGS84. Does anyone know of any Ruby libraries that are available that do this? Or experience with anything that might do this? I had previously done this using a library in .Net/C#, but so far I haven't had much luck tracking ...

Rails CookieStore::CookieOverflow, not for all users, only in production

I have a couple users that are getting this CookieStore::CookieOverflow error. I'm suspicious of nginx/passenger because I just switched to that last week (from nginx/thin) and now these are happening. It's always a particular action, but it doesn't happen for all users. I checked to see what I'm storing in the session and I'm not sav...

Rake db:migrate uninitialized constant

In order to run rake db:migrate I need both my models and constants defined in application controller. When I run it I get this rake aborted! An error has occurred, all later migrations canceled: uninitialized constant Secondsperday All I need is rake to load the environment. It used to do this... Secondsperday is not a model, its t...

acl9 find just model object which satisfys object.accepts_role?(role_name, current_user)

Hello, I'm pretty new to rails and it's the first time I'm actually using authlogic + acl9. I followed the default installation steps for both plugins. So far everything works great, but I have trouble to find an elegant solution for this problem: Let's say I have a model class called Products. When creating a new Product object I ass...

TinyMCE and rails

I am a rails n00b. I want to use tinyMCE instead of a textarea that got created automatically via scaffolding. so Im using tinyMCE hammer. the scaffolding automatically created this line <%= f.text_area :descripcion %> and I substituted it with <%= tinymce(:descripcion) %> When I load the view it looks just fine but when I try to s...

Rails include page

How would I include a page from the public folder in one of my views? I want to include a single header like I do in PHP so when I make a change it affects all the other pages. (It is for multiple views) ...

Re-entrant subrequests in Rack/Rails

I've got a couple Engine plugins with metal endpoints that implement some extremely simple web services I intend to share across multiple applications. They work just fine as they are, but obviously, while loading them locally for development and testing, sending Net::HTTP a get_response message to ask localhost for another page from ins...