Questions tagged [ruby-on-rails]
Ruby on Rails is an open source full-stack web application framework written in Ruby. It follows the popular MVC framework model and is known for its "convention over configuration" approach to application development.
ruby-on-rails
338,329
questions
1583
votes
32
answers
634k
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?
1216
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 ...
1214
votes
15
answers
336k
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 ...
1128
votes
33
answers
574k
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.
1063
votes
11
answers
230k
views
Understanding the Rails Authenticity Token
What is the Authenticity Token in Rails?
1054
votes
20
answers
760k
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?
992
votes
51
answers
437k
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 ...
835
votes
18
answers
578k
views
How to get a random number in Ruby
How do I generate a random number between 0 and n?
760
votes
20
answers
409k
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 ...
736
votes
24
answers
518k
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
441k
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 ...
687
votes
18
answers
662k
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
607k
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
458k
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?