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
172
votes
2 answers

How to get a specific "commit" of a gem from github?

I'm using rails_admin, and since it is in (very) active development, bugs turn up every now and then. There are no versions for the gem as far as I can tell, for the gem in github, so I can't use the :version key for the gem declaration in the…
Zabba
  • 64,285
  • 47
  • 179
  • 207
169
votes
23 answers

Can't find the PostgreSQL client library (libpq)

I'm trying to install PostgreSQL for Rails on Mac OS X 10.6. First I tried the MacPorts install but that didn't go well so I did the one-click DMG install. That seemed to work. I suspect I need to install the PostgreSQL development packages but I…
Jason Swett
  • 43,526
  • 67
  • 220
  • 351
169
votes
20 answers

How to chain scope queries with OR instead of AND?

I'm using Rails3, ActiveRecord Just wondering how can I chain the scopes with OR statements rather than AND. e.g. Person.where(:name => "John").where(:lastname => "Smith") That normally returns: name = 'John' AND lastname = 'Smith' but I'd like:…
168
votes
5 answers

How can I tell Rails to use RSpec instead of test-unit when creating a new Rails app?

I have test-unit installed and rspec installed (along with -core, -expectations, -mocks and -rails version 2.6.x). When I run the command rails new foo, it uses test-unit to generate the test stub files instead of rspec. Is there an option where I…
aarona
  • 35,986
  • 41
  • 138
  • 186
165
votes
7 answers

Adding :default => true to boolean in existing Rails column

I've seen a few questions (namely this one) here on SO about adding a default boolean value to an existing column. So I tried the change_column suggestion but I mustn't be doing it right. I tried: $ change_column :profiles, :show_attribute,…
tvalent2
  • 4,959
  • 10
  • 45
  • 87
163
votes
12 answers

Best way to create unique token in Rails?

Here's what I'm using. The token doesn't necessarily have to be heard to guess, it's more like a short url identifier than anything else, and I want to keep it short. I've followed some examples I've found online and in the event of a collision, I…
Slick23
  • 5,827
  • 10
  • 41
  • 72
163
votes
4 answers

Get Error: You must install at least one postgresql-client- package when deploy to heroku

sdilshod@sdilshod-Lenovo-B590:~/webapp/saturn$ heroku run rake db:migrate Running `rake db:migrate` attached to terminal... up, run.6194 DEPRECATION WARNING: You have Rails 2.3-style plugins in vendor/plugins! Support for these plugins will be…
dilshod
  • 1,831
  • 2
  • 12
  • 11
161
votes
5 answers

Rails 3 check if attribute changed

Need to check if a block of attributes has changed before update in Rails 3. street1, street2, city, state, zipcode I know I could use something like if @user.street1 != params[:user][:street1] then do something.... end But that piece of code…
pcasa
  • 3,710
  • 7
  • 39
  • 67
160
votes
12 answers

Checking if a variable is an integer

Does Rails 3 or Ruby have a built-in way to check if a variable is an integer? For example, 1.is_an_int #=> true "dadadad@asdasd.net".is_an_int #=> false?
AnApprentice
  • 108,152
  • 195
  • 629
  • 1,012
160
votes
10 answers

Best way to add page specific JavaScript in a Rails 3 app?

Rails 3 has some unobtrusive JavaScript which is pretty cool. But I was wondering what the best way is to include additional JavaScript for a particular page. For example, where I might have previously done: <%= f.radio_button :rating, 'positive',…
Brian Armstrong
  • 19,707
  • 17
  • 115
  • 144
158
votes
4 answers

Rails 3 datatypes?

Where can I find a list of data types that can be used in rails 3? (such as text, string, integer, float, date, etc.?) I keep randomly learning about new ones, but I'd love to have a list I could easily refer to.
Elliot
  • 13,580
  • 29
  • 82
  • 118
157
votes
7 answers

Rails 3.1 and Image Assets

I have put all my images for my admin theme in the assets folder within a folder called admin. Then I link to it like normal ie. # Ruby image_tag "admin/file.jpg" ..... #CSS .logo{ background:url('/assets/images/admin/logo.png'); FYI. Just for…
Lee
  • 20,034
  • 23
  • 75
  • 102
157
votes
6 answers

Specifying column name in a "references" migration

I want to make a migration in Rails, referencing another table. Usually, I would do something like: add_column :post, :user, :references This creates a column named user_id in posts table. But what if, instead of user_id, I want something like…
caarlos0
  • 20,020
  • 27
  • 85
  • 160
157
votes
6 answers

Rails: Open link in new tab (with 'link_to')

I have this code: <%= link_to image_tag("facebook.png", :class => "facebook_icon", :alt => "Facebook", :target => "_blank"), "http://www.facebook.com/mypage" %> How can I make it open in a new tab when a user clicks…
Dantes
  • 2,791
  • 6
  • 26
  • 34
155
votes
2 answers

Can someone explain collection_select to me in clear, simple terms?

I am going through the Rails API docs for collection_select and they are god-awful. The heading is this: collection_select(object, method, collection, value_method, text_method, options = {}, html_options = {}) And this is the only sample code they…
marcamillion
  • 32,933
  • 55
  • 189
  • 380