338,339
questions
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?
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 ...
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 ...
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.
1064
votes
11
answers
231k
views
Understanding the Rails Authenticity Token
What is the Authenticity Token in Rails?
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?
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 ...
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?
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 ...
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?
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 ...
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 => ...
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 ...
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 ...
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?