ruby-on-rails

in rails, how to return records as a csv file

I have a simple database table called "Entries": class CreateEntries < ActiveRecord::Migration def self.up create_table :entries do |t| t.string :firstName t.string :lastName #etc. t.timestamps end end def self.down drop_table :entries end end How do I write a handler that will return the c...

Overriding a MIME type in Rails

I want to override the JSON MIME type ("application/json") in Rails to ("text/x-json"). I tried to register the MIME type again in mime_types.rb but that didn't work. Any suggestions? Thanks. ...

Should I use haml or erb or erubis for potentially high traffic site?

I have been playing with Haml recently and really like the way the resulting code looks to me...the developer. I'm also not too worried about a designer being able to consume or change it...we're a small team. That said, beginning work on a project we believe will generate quite a bit of traffic (who doesn't?). I'm concerned that there...

Multiple relations to the same model in Rails

Let's say I have two models, Classes and People. A Class might have one or two People as instructors, and twenty people as students. So, I need to have multiple relationships between the models -- one where it's 1->M for instructors, and one where it's 1->M for students. Edit: Instructors and Students must be the same; instructors could...

Ruby on Rails: no such file to load -- openssl on RedHat Linux Enterprise

I am trying to do 'rake db:migrate' and getting the error message 'no such file to load -- openssl'. Both 'openssl' and 'openssl-devel' packages are installed. Others on Debian or Ubuntu seem to be able to get rid of this by installing 'libopenssl-ruby', which is not available for RedHat. Has anybody run into this and have a solution for...

Rails SSL Requirement plugin -- shouldn't it check to see if you're in production mode before redirecting to https?

Take a look at the ssl_requirement plugin. Shouldn't it check to see if you're in production mode? We're seeing a redirect to https in development mode, which seems odd. Or is that the normal behavior for the plugin? I thought it behaved differently in the past. ...

How do I get Haml to work with Rails?

I am trying to get Haml to work with my Ruby on Rails project. I am new to Ruby on Rails and I really like it. However, when I attempt to add an aplication.html.haml or index.html.haml for a view, I just receive errors. I am using NetBeans as my IDE. Any help would be appreciated. ...

Anyone know of a good Ruby on Rails 2.1 Tutorial?

I'm new to Ruby on Rails, but not to MVC web development, having cut my teeth on Turbogears, Django, etc. I'm having trouble finding a piece of good intro documentation to Ruby on Rails -- either the tutorial is for RoR 1.x, or the tutorial is for RoR 2.1.x, but assumes that you already know how RoR works. Does anyone know of a tutoria...

Can you Distribute a Ruby on Rails Application without Source?

I'm wondering if it's possible to distribute a RoR app for production use without source code? I've seen this post on SO, but my situation is a little different. This would be an app administered by people with some clue, so I'm cool with still requiring an Apache/Mongrel/MySQL setup on the customer end. All I really want is for the s...

When is it appropriate to use Time#utc in Rails 2.1?

I am working on a Rails application that needs to handle dates and times in users' time zones. We have recently migrated it to Rails 2.1 and added time zone support, but there are numerous situations in which we use Time#utc and then compare against that time. Wouldn't that be the same as comparing against the original Time object? When...

"Mysql server has gone away" with Rails

After our rails app has run for a while, it starts throwing 500s with "Mysql server has gone away". Often this happens overnight. It's started doing this recently, with no obvious change in our server configuration. Mysql::Error: MySQL server has gone away: SELECT * FROM `widgets` Restarting the mongrels (not the mysql server) fixes ...

Customising the generic Rails error message

Hello Our rails app is designed as a single code base linking to multiple client databases. Based on the subdomain the app determines which db to connect to. We use liquid templates to customise the presentation for each client. We are unable to customise the generic 'We're Sorry, somethign went wrong..' message for each client. Can a...

What little things do I need to do before deploying a rails application

EDIT What small things which are too easy to overlook do I need to do before deploying a rails application? I have set up another question for any task that takes more than a minute or two, and so ought to be scheduled into a deployment process. In this question I'm mostly concerned with on-line config options and similar, that can be...

Big things to do when deploying a rails app

In the question What little things do I need to do before deploying a rails application I am getting a lot of answers that are bigger than "little things". So this question is slighly different. What reasonably major steps do I need to take before deploying a rails application. In this case, i mean things which are are going to take mo...

Rails-like Database Migrations?

Is there any easy to install/use (on unix) database migration tools like Rails Migrations? I really like the idea, but installing ruby/rails purely to manage my database migrations seems overkill. ...

Rails state of the art for spam prevention

What is the current state of the art in rails for preventing spam accounts? Captcha? Any good plugins, tutorials or suggestions? ...

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,...

Rails Sessions over servers

Hello, I'd like to have some rails apps over different servers sharing the same session. I can do it within the same server but don't know if it is possible to share over different servers. Anyone already did or knows how to do it? 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...