Questions tagged [ruby-on-rails-3]

Ruby on Rails is an open-source web development framework written in Ruby. Ruby on Rails follows the principle of convention over configuration, freeing you from having to re-invent things to stay productive. Use this tag only for Rails 3-specific questions, and also tag those questions [ruby-on-rails].

Ruby on Rails 3.0 was a major revision of Ruby on Rails in 2010, the open-source web development framework designed to make programmers happy and productive. Rails 3.0 brings a bunch of new features and improvements over older Rails versions, including:

  • Brand new router with an emphasis on RESTful declarations
  • New Active Record chainable query language built on top of relational algebra
  • Unobtrusive JavaScript helpers with drivers for Prototype, jQuery
  • Explicit dependency management with Bundler

See Ruby on Rails 3.0 Release Notes for more information.

Multiple sub-versions have been released, namely 3.0, 3.1 and 3.2. Questions regarding specific sub-versions of Ruby on Rails 3.0 can also be asked on the appropriate tags:

Resources:

See also:

56082 questions
19
votes
6 answers

Optionally testing caching in Rails 3 functional tests

Generally, I want my functional tests to not perform action caching. Rails seems to be on my side, defaulting to config.action_controller.perform_caching = false in environment/test.rb. This leads to normal functional tests not testing the…
Stephan
  • 2,853
  • 3
  • 20
  • 25
19
votes
3 answers

Ruby on Rails Application Template

What Rails application templates show best practices for setting up a new Ruby on Rails application? I'm interested in two things. Which application templates are designed well (modular and easily customized)? Which offer the best (or most …
19
votes
3 answers

rails 3 habtm delete only association

class Company has_and_belongs_to_many :users end class User has_and_belongs_to_many :companies end when i delete a company, what's the best (recommended) way to delete ONLY the associations of the users from that company? (i mean not the…
Andrei S
  • 6,486
  • 5
  • 37
  • 54
19
votes
5 answers

ActiveRecord Find All not sorting by ID?

I've got a strange issue on a Heroku deployment that I can't seem to duplicate locally. Basically when I find all on a specific model instead of sorting by ID it seems to return them in no order at all. Typically the records come out like so: >>…
Andrew
  • 42,517
  • 51
  • 181
  • 281
19
votes
1 answer

Rails 3 has_many :through naming issue

Alright, so here's the deal. I have two tables and a join table since it's a many-to-many relationship. I have an order and an order can have many products. Obviously it goes the other way since products can be on many orders. I've got the following…
MattC
  • 12,285
  • 10
  • 54
  • 78
19
votes
4 answers

Preventing Paperclip from deleting/overwriting attachments on update

I'm having a hard time figuring out how to prevent Paperclip from deleting the old version of an attachment (image). I have a model, Site, which has an attachment, logo. I would like to keep the old logos around since I will be keeping track of…
simonwh
  • 1,017
  • 8
  • 21
19
votes
1 answer

How to find the record with the maximum price?

This returns the maxium value, not the complete record: self.prices.maximum(:price_field) And currently, I find the record like this: def maximum_price self.prices.find(:first, :conditions => "price = #{self.prices.maximum(:price_field)}"…
Zabba
  • 64,285
  • 47
  • 179
  • 207
19
votes
15 answers

rails - REGEX for email validation

I'm looking for a regex to validate an email to learn if it's valid or not.. I have the following: def is_a_valid_email?(email) email_regex = %r{ ^ # Start of string [0-9a-z] # First character [0-9a-z.+]+ # Middle characters …
AnApprentice
  • 108,152
  • 195
  • 629
  • 1,012
19
votes
1 answer

rails Select Form Tag - How to add a default "All" option?

I have the following which creates a select box: <%=select_tag "people", options_from_collection_for_select(@people, "id", "name")%> This creates an item for each person, problem is I would like a "All People" value 0, option added and selected by…
AnApprentice
  • 108,152
  • 195
  • 629
  • 1,012
19
votes
1 answer

Where are Rails 3 custom JavaScript events defined?

As I look through the Rails 3 jquery-ujs code, I notice that it binds to custom JavaScript events (submit.rails, click.rails, etc). Does anyone know where are these custom '.rails' events defined? I'm just trying to better understand how the UJS…
Bryan
  • 2,205
  • 1
  • 23
  • 43
19
votes
3 answers

rails - created_at when user for ordering, Should you add an Index to the table?

Hello for one of my models photos I have: default_scope :order => 'photos.created_at DESC, photos.version DESC' Given that I'm ordering by CREATED_AT and Version... Should I have a DB index on CREATED_AT? Thanks
AnApprentice
  • 108,152
  • 195
  • 629
  • 1,012
19
votes
3 answers

How to test Rails 3 Engines with Cucumber & Rspec?

I apologize if this question is slightly subjective... I am trying to figure out the best way to test Rails 3 Engines with Cucumber & Rspec. In order to test the engine a rails 3 app is necessary. Here is what I am currently doing: Add a rails…
johnmcaliley
  • 11,015
  • 2
  • 42
  • 47
19
votes
3 answers

Generate only tests from existing model / controllers

I have a Rails3 app that is based on someone else's work. For some reason they decided not to supply the tests with the app, which I am finding frustrating. What I want to be able to do is scaffold the tests for all the existing controllers and…
kelso
  • 394
  • 1
  • 2
  • 11
19
votes
4 answers

rails - Paperclip file name

using rails with Paperclip, I can use the following to get the filename during a before_create: extension = File.extname(photo_file_name).downcase How do I get JUST the file name.. Right now I have photo_file_name which provides the entire file,…
AnApprentice
  • 108,152
  • 195
  • 629
  • 1,012
19
votes
4 answers

Rails 3 Application/User Settings best practice?

I have a current need for allowing both admin configurable global settings as well as per-user configurable settings within a Rails 3 app. Are there any gems or best practices that work well for this situation? I've found a couple of gems and blog…