resolve rails3 nested resources
Ruby
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
spec
.gitignore
Gemfile
Gemfile.lock
MIT-LICENSE
README.rdoc
Rakefile
nested-resources.gemspec

README.rdoc

nested-resources

Your app has routes like this.

resources :users do
  resources :items
end

In Items controller. You can write controller like this.

class ItemsController < ApplicationController
  nested_resources :user # nested resource

  def index
    @user = nested.instance(User) # find nested resource instance
    @items = @user.items

    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @domains }
    end
  end

...

end

In views.

<%= nested(item_path(@item)) %> # => "/users/1/item"

In form view.

<%= form_for(nested.resource(@item)) do |f| %> => [@user, @item]
  ...
<% end %>

Install

Add to Gemfile

gem 'nested-resources'

Run bundle install

bundle install

TIPS

Has nested path?

nested?(:user)
=> true or false

Deep nested resources like /users/1/items/2/comments

nested_resources [:user, :item]

Recursive resources

resources :users, :as => "parents" do
  resources :users
end

nested_resources :user => :parent

This project rocks and uses MIT-LICENSE.