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 is an open source full-stack web application framework created by David Heinemeier Hansson (DHH) in 2004 using the Ruby programming language. It is an optimized framework aimed at programmer's happiness and providing sustainable productivity by making use of CoC (Convention over Configuration), DRY (Don't Repeat Yourself), Active Record Pattern and REST (Representational State Transfer) philosophies.

It is based on the MVC Architectural Design Pattern, which separates web applications into three different modules:

  • Model
  • View
  • Controller

This helps to isolate business logic from presentation and makes code maintenance significantly easier as well as more flexible.

Ruby is the programming language used by Ruby on Rails

The tag is for questions related to the Ruby on Rails framework. This tag is particularly appropriate for questions about:

  • Rails MVC patterns
  • Rails objects
  • Rails methods
  • Rails gems
  • Rails views
  • Rails routes
  • Rails plugins
  • ActiveRecord object-relational mapping (ORM)

Questions about Ruby on Rails should not be tagged with [tag: ruby] unless the question is about the Ruby language in general, its syntax and libraries, or other questions not specific to the Ruby on Rails MVC framework.

Please see the Ruby tag wiki for more information about when it's appropriate to tag a question with instead of .

Specific Versions

Questions regarding specific versions of Ruby on Rails can also be asked on the appropriate tags:

Where to start

Interactive Ruby

  • Codecademy—Learn the fundamentals of Ruby and dynamic programming

Online Courses

  • Web Application Architectures—Learn how to build and deploy modern web application architectures—applications that run over the Internet, whereas in the "cloud" technology, deploy it using a browser as the user interface. We're going to learn about web apps through the Ruby on Rails framework. Rails is a framework for creating web applications that are built on top of the Ruby programming language.

Resources

Books

When asking Ruby on Rails questions, you should:

  1. Read the API documentation carefully and search Stack Overflow for duplicates.
  2. Mention the Ruby and the Ruby on Rails version related to the issue.
  3. Frame the question in a simple way, add code snippets if that could help the community to understand the problem better.
  4. Tag the question with appropriate tags so that there will be more visits to the page.
  5. Supply error information, if any—console log info is best.

Contributing to the community

  1. If you can solve the problem, spend some time answering the question.
  2. Upvote and downvote appropriately to rate and maintain the quality of questions and answers posted.

Contributing to Ruby on Rails

There are hundreds of people around the world who contribute to Ruby on Rails. You can start by following this guide.

Chat rooms

Related tags

326255 questions
1503
votes
28 answers

Rails: 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
  • 15,229
  • 5
  • 17
  • 11
1165
votes
15 answers

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 whitespace string. For example, "", " ", nil, [], and {}…
Arrel
  • 13,100
  • 7
  • 22
  • 22
1129
votes
15 answers

Why do people use Heroku when AWS is present? What distinguishes Heroku from AWS?

I'm a beginner RoR programmer who's planning to deploy my app using Heroku. Word from my other advisor friends says that Heroku is really easy, good to use. The only problem is that I still have no idea what Heroku does... I've looked at their…
Bryan
  • 11,487
  • 4
  • 13
  • 12
1086
votes
33 answers

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
  • 79,807
  • 86
  • 218
  • 314
1007
votes
10 answers

Understanding the Rails Authenticity Token

I am running into some issues regarding the Authenticity Token in Rails, as I have many times now. But I really don't want to just solve this problem and go on. I would really like to understand the Authenticity token. Well, my question is, do you…
Ricardo Acras
  • 34,766
  • 15
  • 66
  • 109
880
votes
14 answers

How to rollback a specific migration?

I have the following migration file db\migrate\20100905201547_create_blocks.rb How can I specifically rollback that migration file?
AnApprentice
  • 97,752
  • 174
  • 583
  • 971
863
votes
23 answers

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 changed authentication to md5 in pg_hba and tried…
orderof1
  • 8,922
  • 4
  • 15
  • 17
859
votes
43 answers

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 could take a while... ERROR: Error installing pg: …
demonchand
  • 9,861
  • 6
  • 19
  • 25
798
votes
17 answers

How to get a random number in Ruby

How do I generate a random number between 0 and n?
Mark A. Nicolosi
  • 72,599
  • 10
  • 41
  • 46
673
votes
18 answers

How to "pretty" format JSON output in Ruby on Rails

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 problem in the JSON output stream. Is there way to…
JP Richardson
  • 35,950
  • 34
  • 117
  • 150
673
votes
21 answers

How to drop columns using Rails migration

What's the syntax for dropping a database table column through a Rails migration?
Ethan
  • 8,808
  • 4
  • 25
  • 23
660
votes
5 answers

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

The difference between rake db:migrate and rake db:reset is pretty clear in my head. The thing which I don't understand is how rake db:schema:load different from the former two. Just to be sure that I am on the same page: rake db:migrate - Runs the…
Gaurav Agarwal
  • 13,952
  • 4
  • 27
  • 39
634
votes
6 answers

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 or models. I am pretty sure it has to do with…
yagooar
  • 15,789
  • 6
  • 17
  • 21
609
votes
21 answers

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
  • 97,752
  • 174
  • 583
  • 971
602
votes
16 answers

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 => 1, :b => 2}.reject! { |k| k == :a } #=> {:b => 2} but I would expect to…
Misha Moroshko
  • 148,413
  • 200
  • 467
  • 700
1
2 3
99 100