Questions tagged [ruby-on-rails-3]

Ruby on Rails is an open-source web development framework written in Ruby. Ruby on Rails follows the principle of convention over configuration, freeing you from having to re-invent things to stay productive. Use this tag only for Rails 3-specific questions, and also tag those questions [ruby-on-rails].

Ruby on Rails 3.0 was a major revision of Ruby on Rails in 2010, the open-source web development framework designed to make programmers happy and productive. Rails 3.0 brings a bunch of new features and improvements over older Rails versions, including:

  • Brand new router with an emphasis on RESTful declarations
  • New Active Record chainable query language built on top of relational algebra
  • Unobtrusive JavaScript helpers with drivers for Prototype, jQuery
  • Explicit dependency management with Bundler

See Ruby on Rails 3.0 Release Notes for more information.

Multiple sub-versions have been released, namely 3.0, 3.1 and 3.2. Questions regarding specific sub-versions of Ruby on Rails 3.0 can also be asked on the appropriate tags:

Resources:

See also:

56082 questions
140
votes
5 answers

Pass a variable into a partial, rails 3?

I have a loop like such: <% @posts.each do |post| %> <% render middle %> <% end %> Then in my middle partial, how do I access the current post?
Elliot
  • 13,580
  • 29
  • 82
  • 118
139
votes
4 answers

How do I create a class instance from a string name in ruby?

I have the name of a class and I want to create an instance of that class so that I can loop through each rails attribute that is present in the schema of that class. How would I go about doing that? I have the name as a string of the class I want…
mhenrixon
  • 6,179
  • 4
  • 40
  • 64
137
votes
5 answers

NoMethodError: undefined method `last_comment' after upgrading to rake 11

When running any rake task I get: NoMethodError: undefined method `last_comment' for This was after bundle update which pulled in the new version of rake, version 11.0.1. $ grep rake Gemfile.lock rake rake (>= 0.8.7) rake…
Kris
  • 19,188
  • 9
  • 91
  • 111
136
votes
6 answers

Rails Model find where not equal

How can I find records in my database on a not equal condition? I have this now, but is there a fancy rails-speak way of doing it? GroupUser.where('user_id != ?',me)
Colin
  • 2,814
  • 5
  • 27
  • 37
136
votes
15 answers

Rails 3: "field-with-errors" wrapper changes the page appearance. How to avoid this?

Email field: looks like this: But, if the email validation fails, it becomes:
Misha Moroshko
  • 166,356
  • 226
  • 505
  • 746
135
votes
9 answers

ActiveRecord: List columns in table from console

I know that you can ask ActiveRecord to list tables in console using: ActiveRecord::Base.connection.tables Is there a command that would list the columns in a given table?
Andrew
  • 42,517
  • 51
  • 181
  • 281
133
votes
5 answers

Change the name of the :id parameter in Routing resources for Rails

I looked around on how to change the dynamic params slot and found this post that does the exact thing. The post is https://thoughtbot.com/blog/rails-patch-change-the-name-of-the-id-parameter-in Basically what it does is, if following is the…
millisami
  • 9,931
  • 15
  • 70
  • 112
133
votes
3 answers

What is the difference between `after_create` and `after_save` and when to use which?

Are after_create and after_save the same as per functionality? I want to do an operation with the email of a user after its account creation. I want to do that operation when it is saved in the database. which is preferable to use: after_create or…
Swapnil Chincholkar
  • 2,869
  • 3
  • 22
  • 22
133
votes
15 answers

Rails 3: Get Random Record

So, I've found several examples for finding a random record in Rails 2 -- the preferred method seems to be: Thing.find :first, :offset => rand(Thing.count) Being something of a newbie I'm not sure how this could be constructed using the new find…
Andrew
  • 42,517
  • 51
  • 181
  • 281
133
votes
2 answers

Resque vs Sidekiq?

I am currently using Resque for my background process but recently I heard a lot of huff-buff about sidekiq. Could anybody compare/differentiate? In particular I would like to know is there a way to monitor programmatically whether a job is…
Bhushan Lodha
  • 6,824
  • 7
  • 62
  • 100
132
votes
8 answers

Undefined method 'task' using Rake 0.9.0

I just updated Rake to the latest version (0.9.0.beta.4) and the rake command ends up with the following error message: rake aborted! undefined method `task' for # Here is the trace: undefined method `task' for…
Amokrane Chentir
  • 29,907
  • 37
  • 114
  • 158
131
votes
1 answer

Emacs Ruby autocomplete almost working

I've been updating my emacs config with the use of Rsense to allow for an autocomplete drop down box to appear whilst typing code. This works well in most files except I've found it doesn't allow me to select an answer from the table when I'm…
map7
  • 5,096
  • 6
  • 65
  • 128
131
votes
5 answers

Devise form within a different controller

I am using a devise gem for sign_in/sign_out procedures. I generated views files from devise, using rails g devise views I saw there was a devise/sessions/new.html.erb file which contained a form for sign_in. I created another file…
user482594
  • 16,878
  • 21
  • 72
  • 108
129
votes
4 answers

Rails has_and_belongs_to_many migration

I have two models restaurant and user that I want to perform a has_and_belongs_to_many relationship. I have already gone into the model files and added the has_and_belongs_to_many :restaurants and has_and_belongs_to_many :users I assume at this…
128
votes
5 answers

Can you do greater than comparison on a date in a Rails 3 search?

I have this search in Rails 3: Note.where(:user_id => current_user.id, :notetype => p[:note_type], :date => p[:date]).order('date ASC, created_at ASC') But I need the :date => p[:date] condition to be equivilent to :date > p[:date]. How can I do…
ben
  • 29,229
  • 42
  • 124
  • 179