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
18
votes
1 answer

Rails3 - Caching in development mode with Rails.cache.fetch

In development, the following (simplified) statement always logs a cache miss, in production it works as expected: @categories = Rails.cache.fetch("categories", :expires_in => 5.minutes) do Rails.logger.info "+++ Cache missed +++" …
Markus Proske
  • 3,356
  • 3
  • 24
  • 32
18
votes
2 answers

Filter json render in Rails

What is the best way if i would like to only return :id and :name fields in JSON So far i have: format.json { render :json => @contacts.map(&:attributes) , :only => ["id"]} But the "name" attribute does not work in the :only section, since it is…
montrealmike
  • 11,433
  • 10
  • 64
  • 86
18
votes
5 answers

Git-based content management?

I'm looking for a Ruby CMS (or plugin) that can serve and edit content located in a Git repository. I'm sick of having my content in a db. Users, settings, comments, fine. But no more content. Each live edit to a page will need to be automatically,…
Lilith River
  • 16,204
  • 2
  • 44
  • 76
18
votes
2 answers

What does the * (asterisk) symbol do near a function argument and how to use that in others scenarios?

I am using Ruby on Rails 3 and I would like to know what means the presence of a * operator near a function argument and to understand its usages in others scenarios. Example scenario (this method was from the Ruby on Rails 3 framework): def…
user502052
  • 14,803
  • 30
  • 109
  • 188
18
votes
3 answers

rails - how to render a JSON object in a view

right now I'm creating an array and using: render :json => @comments This would be fine for a simple JSON object, but right now my JSON object requires several helpers which is breaking everything and requiring helper includes in the controller…
AnApprentice
  • 108,152
  • 195
  • 629
  • 1,012
18
votes
2 answers

Rails Namespace vs. Nested Resource

Let's say my app has two models, Foo and Bar. Foo optionally belongs_to Bar. Right now I can look at a single Foo, or search for a particular Foo, and the FoosController handles all that. My URLS are like: foos/1 and foos/new Sometimes I want to…
Andrew
  • 42,517
  • 51
  • 181
  • 281
18
votes
2 answers

How do I validate a non-model form in Rails 3?

Let's say I have a search form and I want to validate the length of the keyword. I want the form to highlight the invalid field (like model forms). I've looked everywhere and can't seem to find any useful information on validating non-model-backed…
Mike
  • 335
  • 1
  • 5
  • 10
18
votes
4 answers

Rails: radio button selection for nested objects

I'm stuck with this simple selection task. I have this models: # id :integer(4) not null, primary key # category :string(255) # content :text class Question < ActiveRecord::Base has_many :choices, :dependent => :destroy …
18
votes
1 answer

How to add `:include` to default_scope?

Searching the 'net, I found that I should use :include, but that does not seem to change the SQL query that is generated: def Post #model default_scope :order => 'created_at DESC', :include => :author end With or without the :include, the SQL is…
Zabba
  • 64,285
  • 47
  • 179
  • 207
18
votes
5 answers

How to test cookies.permanent.signed in Rails 3

I have a action in some controller that set some value in a permanent signed cookie like this: def some_action cookies.permanent.signed[:cookie_name] = "somevalue" end And in some functional test, I'm trying to test if the cookie was set…
Joao Pereira
  • 2,454
  • 4
  • 27
  • 35
18
votes
1 answer

How to use 'after_initialize' in Rails 3?

UPDATE I wrongly checked the edgerails guide instead of the currently correct Rails 3 guide (which has no mention of after_initialize). Not sure why the edgerails guide is "incorrect" though - I thought edgerails guide was supposed to be the latest…
Zabba
  • 64,285
  • 47
  • 179
  • 207
18
votes
1 answer

When using 'gemspec' in a Gemfile how do I do the :require => 'foo'

The gem has a few development dependencies like ruby-debug19 and sqlite3-ruby where the gem name and the require are different. We handle this in the Gemfile by using the :require => 'foo' option. e.g. gem "sqlite3-ruby", :require =>…
gduq
  • 1,434
  • 11
  • 13
18
votes
6 answers

How do you route an action to the application controller in Rails 3?

I am using the gem rails3-jquery-autocomplete and had no problems with it, however I have now moved my autocomplete form into the application template and therefore the ajax calls are now being dealt by the application controller, so my routes have…
18
votes
3 answers

Rails Nested Singular Resource Routing

I have a simple User model with a singular nested Profile resource so in my routes.rb I have: resources :users do resource :profile, :only => [:edit, :update, :show] end This generates the expected routes: edit_user_profile GET …
18
votes
2 answers

Validators, password confirmation

I can't figure out why the model doesen't check for the password confirmation, this is the code of the model: class User < ActiveRecord::Base attr_accessor :password_confirmation validates :email, :presence =>true, …
Joe
  • 1,747
  • 3
  • 17
  • 24
1 2 3
99
100