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

337315 questions
635
votes
22 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
  • 108,152
  • 195
  • 629
  • 1,012
619
votes
7 answers

Begin, Rescue and Ensure in Ruby?

I've recently started programming in Ruby, and I am looking at exception handling. I was wondering if ensure was the Ruby equivalent of finally in C#? Should I have: file = File.open("myFile.txt", "w") begin file << "#{content} \n" rescue …
Lloyd Powell
  • 18,270
  • 17
  • 87
  • 123
597
votes
1 answer

Ruby on Rails Server options

The whole issue of setting up a development server for my Ruby on Rails application confuses me. There are WEBrick, Mongrel, Passenger, Apache, Nginx and many more I am sure, and I don't really understand the different roles they play. I started off…
pingu
  • 8,719
  • 12
  • 50
  • 84
578
votes
24 answers

Rails DB Migration - How To Drop a Table?

I added a table that I thought I was going to need, but now no longer plan on using it. How should I remove that table? I've already run migrations, so the table is in my database. I figure rails generate migration should be able to handle this, but…
569
votes
10 answers

`require': no such file to load -- mkmf (LoadError)

I was trying to install rails on Ubuntu Natty Narwhal 11.04, using ruby1.9.1. I installed ruby using apt-get install ruby1.9.1-full which contains the dev package. I googled the error and all have suggested I install the 1.9.1-dev which I already…
Omar
  • 8,374
  • 8
  • 39
  • 50
527
votes
33 answers

Error installing mysql2: Failed to build gem native extension

I am having some problems when trying to install mysql2 gem for Rails. When I try to install it by running bundle install or gem install mysql2 it gives me the following error: Error installing mysql2: ERROR: Failed to build gem native…
spacemonkey
  • 19,664
  • 14
  • 42
  • 62
516
votes
12 answers

How to redirect to a 404 in Rails?

I'd like to 'fake' a 404 page in Rails. In PHP, I would just send a header with the error code as such: header("HTTP/1.0 404 Not Found"); How is that done with Rails?
Yuval Karmi
  • 26,277
  • 39
  • 124
  • 175
508
votes
25 answers

Undo scaffolding in Rails

Is there any way to 'undo' the effects of a scaffold command in Rails?
Daniel
  • 16,026
  • 18
  • 65
  • 89
486
votes
8 answers

How do I make a column unique and index it in a Ruby on Rails migration?

I would like to make a column unique in Ruby on Rails migration script. What is the best way to do it? Also is there a way to index a column in a table? I would like to enforce unique columns in a database as opposed to just using…
Tam
  • 11,872
  • 19
  • 69
  • 119
481
votes
9 answers

Difference between string and text in rails?

I'm making a new web app using Rails, and was wondering, what's the difference between string and text? And when should each be used?
Mo.
  • 40,243
  • 37
  • 86
  • 131
471
votes
12 answers

What is the easiest way to duplicate an activerecord record?

I want to make a copy of an ActiveRecord object, changing a single field in the process (in addition to the id). What is the simplest way to accomplish this? I realize I could create a new record, and then iterate over each of the fields copying…
Brent
  • 16,259
  • 12
  • 42
  • 42
471
votes
14 answers

How can I call controller/view helper methods from the console in Ruby on Rails?

When I load script/console, sometimes I want to play with the output of a controller or a view helper method. Are there ways to: simulate a request? call methods from a controller instance on said request? test helper methods, either via said…
kch
  • 77,385
  • 46
  • 136
  • 148
470
votes
9 answers

How do I handle too long index names in a Ruby on Rails ActiveRecord migration?

I am trying to add a unique index that gets created from the foreign keys of four associated tables: add_index :studies, ["user_id", "university_id", "subject_name_id", "subject_type_id"], :unique => true The database’s limitation for the index…
JJD
  • 50,076
  • 60
  • 203
  • 339
461
votes
3 answers

In Ruby on Rails, what's the difference between DateTime, Timestamp, Time and Date?

In my experience, getting dates/times right when programming is always fraught with danger and difficulity. Ruby and Rails have always eluded me on this one, if only due to the overwhelming number of options; I never have any idea which I should…
Nick
  • 4,765
  • 3
  • 17
  • 9
449
votes
29 answers

Rails: How can I set default values in ActiveRecord?

How can I set default value in ActiveRecord? I see a post from Pratik that describes an ugly, complicated chunk of code: http://m.onkey.org/2007/7/24/how-to-set-default-values-in-your-model class Item < ActiveRecord::Base def…
ryw
  • 9,375
  • 5
  • 27
  • 34