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
421
votes
5 answers

Rails 4: List of available datatypes

Where can I find a list of data types that can be used in Ruby on Rails 4? Such as text string integer float date I keep learning about new ones and I'd love to have a list I could easily refer to.
Nicolas Raoul
  • 55,003
  • 52
  • 197
  • 338
419
votes
5 answers

How do you write a migration to rename an ActiveRecord model and its table in Rails?

I'm terrible at naming and realize that there are a better set of names for my models in my Rails app. Is there any way to use a migration to rename a model and its corresponding table?
readonly
  • 306,152
  • 101
  • 198
  • 201
408
votes
5 answers

How do I get the name of a Ruby class?

How can I get the class name from an ActiveRecord object? I have: result = User.find(1) I tried: result.class # => User(id: integer, name: string ...) result.to_s # => #" I need only the class name, in a string (User in this case).…
andi
  • 13,928
  • 9
  • 44
  • 46
395
votes
4 answers

Rails update_attributes without save?

Is there an alternative to update_attributes that does not save the record? So I could do something like: @car = Car.new(:make => 'GMC') #other processing @car.update_attributes(:model => 'Sierra', :year => "2012", :looks => "Super Sexy, wanna make…
tybro0103
  • 43,805
  • 32
  • 138
  • 167
392
votes
29 answers

No route matches "/users/sign_out" devise rails 3

I've installed devise on my app and applied the following in my application.html.erb file:
<% if user_signed_in? %> Signed in as <%= current_user.email %>. This cannot be cheese? <%= link_to 'Sign out',…
vich
  • 11,638
  • 13
  • 46
  • 60
388
votes
29 answers

Using Rails 3.1, where do you put your "page specific" JavaScript code?

To my understanding, all of your JavaScript gets merged into 1 file. Rails does this by default when it adds //= require_tree . to the bottom of your application.js manifest file. This sounds like a real life-saver, but I am a little concerned…
387
votes
6 answers

How can I specify a local gem in my Gemfile?

I'd like Bundler to load a local gem. Is there an option for that? Or do I have to move the gem folder into the .bundle directory?
picardo
  • 23,016
  • 32
  • 98
  • 148
387
votes
5 answers

Rails I18n validation deprecation warning

I just updated to rails 4.0.2 and I'm getting this warning: [deprecated] I18n.enforce_available_locales will default to true in the future. If you really want to skip validation of your locale you can set I18n.enforce_available_locales = false to…
Mauricio Moraes
  • 6,889
  • 5
  • 34
  • 54
385
votes
7 answers

What is the difference between <%, <%=, <%# and -%> in ERB in Rails?

Can some one please describe the usage of the following characters which is used in ERB file: <% %> <%= %> <% -%> <%# %> what's the usage of each one ?
simo
  • 20,548
  • 31
  • 101
  • 188
385
votes
7 answers

Can Rails Routing Helpers (i.e. mymodel_path(model)) be Used in Models?

Say I have a Rails Model called Thing. Thing has a url attribute that can optionally be set to a URL somewhere on the Internet. In view code, I need logic that does the following: <% if thing.url.blank? %> <%= link_to('Text', thing_path(thing))…
Aaron Longwell
  • 7,963
  • 5
  • 19
  • 10
378
votes
14 answers

How can I disable logging of asset pipeline (sprockets) messages in Ruby on Rails 3.1?

Sprockets tends to be quite verbose in the (dev) log by default under Ruby on Rails 3.1 (RC1): Started GET "/assets/application.css" for 127.0.0.1 at 2011-06-10 17:30:45 -0400 Compiled app/assets/stylesheets/application.css.scss (5ms) (pid…
372
votes
5 answers

Rails where condition using NOT NIL

Using the rails 3 style how would I write the opposite of: Foo.includes(:bar).where(:bars=>{:id=>nil}) I want to find where id is NOT nil. I tried: Foo.includes(:bar).where(:bars=>{:id=>!nil}).to_sql But that returns: => "SELECT \"foos\".*…
SooDesuNe
  • 9,472
  • 9
  • 52
  • 88
368
votes
7 answers

What does bundle exec rake mean?

What does bundle exec rake db:migrate mean? Or just bundle exec rake in general? I understand that bundle takes care of maintaining things in the Gemfile. I know what the word "exec" means. I understand that rake maintains all the…
JnBrymn
  • 21,527
  • 26
  • 95
  • 140
362
votes
5 answers

How to convert a ruby hash object to JSON?

How to convert a ruby hash object to JSON? So I am trying this example below & it doesn't work? I was looking at the RubyDoc and obviously Hash object doesn't have a to_json method. But I am reading on blogs that Rails supports active_record.to_json…
kapso
  • 10,921
  • 14
  • 53
  • 72
353
votes
8 answers

Rails :include vs. :joins

This is more of a "why do things work this way" question rather than a "I don't know how to do this" question... So the gospel on pulling associated records that you know you're going to use is to use :include because you'll get a join and avoid a…
Rob Cameron
  • 9,346
  • 7
  • 37
  • 41