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
1569
votes
32 answers

How can I rename a database column in a Ruby on Rails migration?

I wrongly named a column hased_password instead of hashed_password. How do I update the database schema, using migration to rename this column?
user1994764
  • 15,889
  • 5
  • 19
  • 11
969
votes
49 answers

Can't find the 'libpq-fe.h header when trying to install pg gem

I am using the Ruby on Rails 3.1 pre version. I like to use PostgreSQL, but the problem is installing the pg gem. It gives me the following error: $ gem install pg Building native extensions. This could take a while... ERROR: Error installing pg: …
demonchand
  • 11,091
  • 6
  • 21
  • 25
825
votes
18 answers

How to get a random number in Ruby

How do I generate a random number between 0 and n?
Mark A. Nicolosi
  • 82,413
  • 11
  • 44
  • 46
673
votes
18 answers

How to remove a key from Hash and get the remaining hash in Ruby/Rails?

To add a new pair to Hash I do: {:a => 1, :b => 2}.merge!({:c => 3}) #=> {:a => 1, :b => 2, :c => 3} Is there a similar way to delete a key from Hash ? This works: {:a => 1, :b => 2}.reject! { |k| k == :a } #=> {:b => 2} but I would expect to…
Misha Moroshko
  • 166,356
  • 226
  • 505
  • 746
635
votes
22 answers

Purge or recreate a Ruby on Rails database

I have a dev Ruby on Rails database full of data. I want to delete everything and rebuild the database. I'm thinking of using something like: rake db:recreate Is this possible?
AnApprentice
  • 108,152
  • 195
  • 629
  • 1,012
578
votes
24 answers

Rails DB Migration - How To Drop a Table?

I added a table that I thought I was going to need, but now no longer plan on using it. How should I remove that table? I've already run migrations, so the table is in my database. I figure rails generate migration should be able to handle this, but…
516
votes
17 answers

How to reverse a 'rails generate'

I want to delete all the files it created and roll back any changes made, but not necessarily to the database, but more to the config files. I'd like to automatically delete all the resource mappings for the model/controller deleted in the routes.rb…
marcamillion
  • 32,933
  • 55
  • 189
  • 380
438
votes
6 answers

How can I specify a local gem in my Gemfile?

I'd like Bundler to load a local gem. Is there an option for that? Or do I have to move the gem folder into the .bundle directory?
picardo
  • 24,530
  • 33
  • 104
  • 151
424
votes
11 answers

Adding a column to an existing table in a Rails migration

I have a Users model which needs an :email column (I forgot to add that column during the initial scaffold). I opened the migration file and added t.string :email, did rake db:migrate, and got a NoMethodError. Then I added the line add_column…
John
  • 5,835
  • 8
  • 28
  • 36
421
votes
4 answers

Rails update_attributes without save?

Is there an alternative to update_attributes that does not save the record? So I could do something like: @car = Car.new(:make => 'GMC') #other processing @car.update_attributes(:model => 'Sierra', :year => "2012", :looks => "Super Sexy, wanna make…
tybro0103
  • 48,327
  • 33
  • 144
  • 170
397
votes
31 answers

No route matches "/users/sign_out" devise rails 3

I've installed devise on my app and applied the following in my application.html.erb file:
<% if user_signed_in? %> Signed in as <%= current_user.email %>. This cannot be cheese? <%= link_to 'Sign out',…
vich
  • 11,836
  • 13
  • 49
  • 66
383
votes
18 answers

How to empty a Heroku database

I'm working on a Ruby on Rails 3 webapp on Heroku. How do I empty the database?
user591338
378
votes
14 answers

How can I disable logging of asset pipeline (sprockets) messages in Ruby on Rails 3.1?

Sprockets tends to be quite verbose in the (dev) log by default under Ruby on Rails 3.1 (RC1): Started GET "/assets/application.css" for 127.0.0.1 at 2011-06-10 17:30:45 -0400 Compiled app/assets/stylesheets/application.css.scss (5ms) (pid…
375
votes
16 answers

How to run a single RSpec test?

I have the following file: /spec/controllers/groups_controller_spec.rb What command in terminal do I use to run just that spec and in what directory do I run the command? My gem file: # Test ENVIRONMENT GEMS group :development, :test do gem…
AnApprentice
  • 108,152
  • 195
  • 629
  • 1,012
372
votes
18 answers

Separate REST JSON API server and client?

I'm about to create a bunch of web apps from scratch. (See http://50pop.com/code for overview.) I'd like for them to be able to be accessed from many different clients: front-end websites, smartphone apps, backend webservices, etc. So I really want…
sivers
  • 3,833
  • 3
  • 14
  • 7
1
2 3
99 100