ruby-on-rails

With Rails, where should I put html snippets? I don't want partials but I want them reloaded during development.

Being lazy (and liking DRY code), I'm the kind of guy who's going to write a few little wrappers for recurring HTML markup. Those provided by Rails are good already, but sometimes I have something a little more specific that I know I'm going to repeat over and over. In some situations a partial can be the solution, but sometimes I'm jus...

Performing AJAX delete operations restfully in rails

How do you perform delete and put operations restfully in rails? I have read the documentation and thought I was doing everything properly, but I can't seem to get it to work. For example, if I wanted to delete an employee I would create a controller called "EmployeesController" and create a destroy method to perform the delete. Then I...

What do you need to take into consideration when deciding between MySQL and Amazon's SimpleDB for a RoR app?

I am just beginning to do research into the feasibility of using Amazon's SimpleDB service as the datastore for RoR application I am planning to build. We will be using EC2 for the web server, and had planned to also use EC2 for the MySQL servers. But now the question is, why not use SimpleDB? The application will (if successful) need t...

Error Updating a record

I get a mysql error: #update (ActiveRecord::StatementInvalid) "Mysql::Error: #HY000Got error 139 from storage engine: When trying to update a text field on a record with a string of length 1429 characters, any ideas on how to track down the problem? Below is the stacktrace. from /var/www/releases/20081002155111/vendor/rails/activere...

Tutorial for creating rails models and scaffolds with foreign key relationships

Where can I find a good Rails newbie-friendly reference about generating rails models with foreign key relationships? I've found some pages indicating that you should add has_many and belongs_to to the relevant models to specify these relationships, but haven't seen any instructions for getting the scaffolds to generate the correct co...

To Nest or Not to Nest?

Premise: Usually during preparation of a new Ruby on Rails App, I draw out models and relations regarding user navigations. Usually I hit a place where I need to ask myself, whether or not I should go beyond the usual "rule of thumb" of nesting no more 1 level deep. Sometimes I feel the need to nest, rather than creating another namespac...

Limitations in running Ruby/Rails on windows

In the installation documentation to RoR it mentions that there are many limitations to running Ruby on Rails on Windows, and in some cases, whole libraries do not work. How bad are these limitations, should I always default to Linux to code / run RoR, and is Iron Ruby expected to fix these limitations or are they core to the OS itself?...

In Ruby on Rails, how do I format a date with the "th" suffix, as in, "Sun Oct 5th"?

I want to display dates in the format: short day of week, short month, day of month without leading zero but including "th", "st", "nd", or "rd" suffix. For example, the day this question was asked would display "Thu Oct 2nd". I'm using Ruby 1.8.7, and Time.strftime just doesn't seem to do this. I'd prefer a standard library if one ex...

Rails named_scopes with joins

I'm trying to create a named_scope that uses a join, but although the generated SQL looks right, the result are garbage. For example: class Clip < ActiveRecord::Base named_scope :visible, { :joins => "INNER JOIN series ON series.id = clips.owner_id INNER JOIN shows on shows.id = series.show_id", :conditions=>"shows.visi...

What deployment directories do you use for Rails applications (deploying to a debian box)?

I wonder what's the best deployment directory for Rails apps? Some developers use directories such as /u/apps/#{appname}. Are there any advantages when using /u/apps/#{appname} instead of /var/www/#{appname} or other OS default directories? Obviously I want to pick the directory with the best security properties and the least friction f...

Multiple database connection

Hi, I'm trying to understand the best way to get the connection to my databases. At the moment I've got a method wich parses the url (depending on the url called the application has to connect to a different database, like customer1.xxx.com will connect to the customer1 database) and calls ActiveRecord::Base.establish_connection(conn...

RSpec Stories and Specs: When to use what?

So I want to start using RSpec stories, but I am not sure where writing controller, model and view specs fit in. For example, you have the story "Logging in" with "User provides wrong password" scenario, don't you end up testing the same stuff than controller/model specs (response.should render..., user.should be_nil, etc.) So my ques...

non-DB attr_accessor attribute persistence in Rails

I have an application in which attr_accessor is being used to keep temporary data for a model which will be passed to a rake task. Seeing there is not a database field for these attributes and they are not being calculated from database data, will the attr_accessor data persist and be available to the rake task? What happens if I need ...

What is the simplest way to allow a user to drag and drop table rows in order to change their order?

I have a Ruby on Rails application that I'm writing where a user has the option to edit an invoice. They need to be able to reassign the order of the rows. Right now I have an index column in the db which is used as the default sort mechanism. I just exposed that and allowed the user to edit it. This is not very elegant. I'd li...

Merging Rails databases

I have two databases with the same structure. The tables have an integer as a primary key as used in Rails. If I have a patients table, I will have one patient using primary key 123 in one database and another patient using the same primary key in the other database. What would you suggest for merging the data from both databases? ...

Rspec - problems with switching from plugins to gems

When dropping the use of rspec and rspec-rails plugins and switching to the gem versions instead, is there anything extra I have to change in spec_helper.rb or something to make the specs in my app see the change? I can no longer get my specs to run successfully anymore after deleting the plugins and installing the gems (1.1.8). More...

Errors when trying to update ruby gems from 2.0.1

I am trying to set myself up on a mac to learn Ruby on Rails, however I seem to be having some problems. If I try to run commands such as ./script/server, i get this: Rails requires RubyGems >= 0.9.4 (you have 0.9.2). Please gem update --system and try again. When I run "gem update.." I get this: Updating RubyGems... Attempting remot...

is it time to try merb?

With Merb 1.0 rapidly approaching, I would like to know what Merb/Rails users recommend? Is it time to try Merb? What was downside for you when you switched to Merb from Rails? ...

Date class different in Ruby stdlib and Rails stdlib

I want to use the Date::ABBR_MONTHS constant in my rails application. I see the Ruby stdlib documentation at http://www.ruby-doc.org/stdlib/ which does not seem to have this constant. However, this constant is there at http://stdlib.rubyonrails.org/ What is the difference between these two libraries? This constant is working on my uni...

What is the best way to validate a terminal command has run successfully in Rails?

I'm writing a quick Rails app and was wondering how I can validate the success an exec'd command. The two commands I'm running are and SVN update, and a cp from one directory to another. ...