ruby-on-rails

How do I get the number of seconds between two DateTimes in Ruby on Rails

I've got code that does time tracking for employees. It creates a counter to show the employee how long they have been clocked in for. This is the current code: start_time = Time.parse(self.settings.first_clock_in) total_seconds = Time.now - start_time hours = (total_seconds/ 3600).to_i minutes = ((total_seconds % 3600) / 60)....

Are Ruby class member variables OK now?

Hi, Last May at Railsconf on Portland, I went to a presentation where it was argued that, in Rails, Ruby class member variables, like @@foo, are dangerous because they are inherently unthreadsafe. I researched the question afterward and I never found a link that really fleshed out the question. I would appreciate a pointer to a good ...

What Rails plugins would you like to see?

What behavior have you had to implement in your Rails applications that you feel could exist nicely as a plugin? What plugin functionality have you searched for in the past but couldn't find? What existing Rails plugins could be improved or extended, and how? ...

Using collection_select view helper for objects in a HABTM relationship

The models project and category are in a has_and_belongs_to_many relationship. The partial seen below is used on different views to show a dropdown-menu with all the available categories. The projects in the list below the dropdown-menu are shown according to the choice the user made in the dropdown-menu. Besides other categories, there...

Getting the name of an instance variable

Looking through the rails 2.3 RC1 release note I see this: # Equivalent of render :partial => 'articles/_article', :object => @article render @article So somehow the render method is finding out the that object passed int it is assigned to an instance variable with the name article. How does it do this? ...

Populate a constant values table

In a Rails application, I need a table in my database to contain constant data. This table content is not intended to change for the moment but I do not want to put the content in the code, to be able to change it whenever needed. I tried filling this table in the migration that created it, but this does not seem to work with the test...

Can Rails / Mongrel accept a form POST with a text field whos value is a URL

In my Rails app I am attempting to create a form that allows users to create a bookmark. <% form_tag( contents_path ) do %> <input name='item_type' value="Bookmark" type="hidden" /></p> <h3>Create New Bookmark</h3> <p>Title:<input name='item[title]' type="text" /></p> <p>URL:<input name='item[url]' type="text" /></p> <%= submi...

Problem saving model in Rails

I'm building a simple blog with comments. There is a Post model and a Comment model. Every interaction between the two works fine except for creating new comments. I'm having an issue in Rails when trying to post a new comment: wrong number of arguments (1 for 0) Here are the request parameters (from the stack trace): {"commit"=>"Pos...

Hosted Email for Rails App

I'm looking for an alternative to Google Apps for sending email from my rails app. (Google limits the number of messages you can send). Do most people roll their own, or is their a preferred provider? I'd love to be able to dynamically create addresses for my customers: [email protected] ...

Add fields to ActiveRecord model dynamically in Rails 2.2.2?

Say I wanted to allow an administrative user to add a field to an ActiveRecord Model via an interface in the Rails app. I believe the normal ActiveRecord::Migration code would be adequate for modifying the AR Model's table structure (something that would not be wise for many applications - I know). Of course, only certain types of fiel...

Help using Flotilla and Ruby on Rails

I'm new to Rails (and StackOverflow), so I apologize if this is a "dumb" question. I've put together a really simple Rails application. It receives data from another server (via HTTP POSTs). I would like to graph the data sent - in particular, I am looking to graph temperature versus time. I am trying to use Flotilla to generate these g...

RJS: Using observe_field on select_tag

The dropdown-menu (built by the select_tag) in my application should call the filter-category-action as soon as the user changes the value in the dropdown-menu AND hits the 'Go' button. Now I'd like to get rid of the 'Go' button and have an observer (observe_field?) call the filter-category-action as soon as the user changes the value ...

Ruby/Rails Audio Conversion Plugins?

I am looking for a good gem/plugin to convert user-uploaded audio files to different formats. One format in particular that I am interested in is converting to Apple .caf with ima4 compression for inclusion in an iPhone app. I have been using afconvert on my mac for this so far, but I need to do it on my linux box, server-side. Ideall...

Is there a library to do CSS spriting automatically?

CSS Spriting can really help performance, but it's not the easiest thing to read and maintain. Are there any tools that would let me code the images individually but aggregate them up and replace the HTML with the correct subset of the montage? I'm specifically thinking a Ruby on Rails plugin, but if there's a package for another langu...

How do I use "gets" on a rake task?

I get an error whenever I try to use the function gets within a rake task. Is there a way to make it work? The error says, "no such file or directory - (rake task name)" ...

Difference between \A \Z and ^ $ in Ruby on Rails regular expressions

In the documentation I read: use \A and \Z to match the start and end of the string, ^ and $ match the start/end of a line I am going to apply a regular expression to check username (or e-mail is the same) submitted by user. Which expression should I use with validates_format_of in model? I can't understand the difference: I've alw...

How to implement undirected graph in Ruby on Rails?

I need to implement a undirected graph G = (V,E) in Ruby on Rails and thought of building a Vertex and an Edge model where *Vertex has_many Edges*. As an edge connects exactly two vertices, how would you enforce this in Rails? Do you know any gem or library that would help implementing such a graph (not intrested in re-inventing the w...

how to set subdomain for length of integration test on multi-site app?

what's the best way to change a subdomains for the duration of an integration test? jamis buck suggested using host! here: http://weblog.jamisbuck.org/2006/3/9/integration-testing-in-rails-1-1#12 but according to the rails API, host! only changes the host for the following single request. i'm looking for something like @request.host...

Going from 2 to many in Rails

I have a Rails application that I'm in the process of designing. I have a separate model that needs to link to only 2 of one model. Specifically, my "evaluation"s have 2 "member"s, an evaluator, and an evaluatee. They also have a few other pieces of information, too but they should not be relevant to this. What is the best way to r...

What is the best web server for ruby on rails application?

What is the best web server for ruby on rails application? Why? ...