Skip to main content
Filter by
Sorted by
Tagged with
1586 votes
32 answers
636k views

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's user avatar
  • 16.1k
1223 votes
28 answers
1.2m views

Getting error: Peer authentication failed for user "postgres", when trying to get pgsql working with rails

I'm getting the error: FATAL: Peer authentication failed for user "postgres" when I try to make postgres work with Rails. Here's my pg_hba.conf, my database.yml, and a dump of the full trace. I ...
orderof1's user avatar
  • 12.6k
1217 votes
15 answers
338k views

How to understand nil vs. empty vs. blank in Ruby

I find myself repeatedly looking for a clear definition of the differences of nil?, blank?, and empty? in Ruby on Rails. Here's the closest I've come: blank? objects are false, empty, or a ...
Arrel's user avatar
  • 13.6k
1129 votes
33 answers
575k views

How do I get the current absolute URL in Ruby on Rails?

How can I get the current absolute URL in my Ruby on Rails view? The request.request_uri only returns the relative URL.
Jakub Arnold's user avatar
  • 86.9k
1064 votes
11 answers
231k views

Understanding the Rails Authenticity Token

What is the Authenticity Token in Rails?
Ricardo Acras's user avatar
1058 votes
20 answers
769k views

How can I rollback a specific migration?

I have the migration file db\migrate\20100905201547_create_blocks.rb. How can I specifically rollback that migration file?
AnApprentice's user avatar
995 votes
51 answers
440k views

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 ...
demonchand's user avatar
  • 11.4k
838 votes
18 answers
581k views

How to get a random number in Ruby

How do I generate a random number between 0 and n?
Mark A. Nicolosi's user avatar
764 votes
20 answers
412k views

How to "pretty" format JSON output

I would like my JSON output in Ruby on Rails to be "pretty" or nicely formatted. Right now, I call to_json and my JSON is all on one line. At times this can be difficult to see if there is a ...
JP Richardson's user avatar
738 votes
24 answers
520k views

How to drop columns using Rails migration

What's the syntax for dropping a database table column through a Rails migration?
Ethan's user avatar
  • 9,748
727 votes
6 answers
444k views

Difference between rake db:migrate db:reset and db:schema:load

The difference between rake db:migrate and rake db:reset is pretty clear to me. The thing which I don't understand is how rake db:schema:load is different from the former two. Just to be sure that I ...
Gaurav Agarwal's user avatar
689 votes
18 answers
668k views

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 => ...
Misha Moroshko's user avatar
647 votes
6 answers
248k views

How to use concerns in Rails 4

The default Rails 4 project generator now creates the directory "concerns" under controllers and models. I have found some explanations about how to use routing concerns, but nothing about controllers ...
yagooar's user avatar
  • 16k
646 votes
66 answers
609k views

Postgres could not connect to server

After I did brew update and brew upgrade, my postgres got some problem. I tried to uninstall postgres and install it again, but it didn't work as well. This is the error message. (I also got this ...
Gary Lai's user avatar
  • 6,623
638 votes
24 answers
461k views

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's user avatar

15 30 50 per page
1
2 3 4 5
22556