Skip to main content
The 2024 Developer Survey results are live! See the results

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.

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?
user1994764's user avatar
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 ...
orderof1's user avatar
  • 12.5k
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 ...
Arrel's user avatar
  • 13.6k
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.
Jakub Arnold's user avatar
  • 86.7k
1063 votes
11 answers
230k views

Understanding the Rails Authenticity Token

What is the Authenticity Token in Rails?
Ricardo Acras's user avatar
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?
AnApprentice's user avatar
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 ...
demonchand's user avatar
  • 11.4k
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?
Mark A. Nicolosi's user avatar
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 ...
JP Richardson's user avatar
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?
Ethan's user avatar
  • 9,728
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 ...
Gaurav Agarwal's user avatar
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 => ...
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
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 ...
Gary Lai's user avatar
  • 6,623
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?
AnApprentice's user avatar

15 30 50 per page
1
2 3 4 5
22556