<commit_before>= automatic_resources

Anyone who's had to deal with nested resources knows that it can get really
messy to have to make everything conditional to support them. Basically it's
just a pain in the ass. If you want to support a nesting structure like the one
in the example below you'll be looking at a big tangled bowl of spaghetti in no
time.

Automatic Resources saves you the trouble. It dynamically defines finder
methods in your controllers and helpers as well as simple named urls that are
100% compatible with the standard ones but produce beautiful nested resource
urls just like you should expect them to.

== Compatible

Automatic Resources doesn't delve into Rails internals or do anything your
grandmother would disapprove of. You can expect it to keep on keepin' on.

== Example

  map.resources :blogs do |blog|
    blog.resources :categories, :has_many => [:posts]
    blog.resources :posts
  end

  class PostsController < ApplicationController
    automatic_resources :blog, :category, :post

    def show
      @blog_name = blog.name if blog?
      @category_name = category.name if category?
      @title = post.title
    end

    def new
      # parent is 
      @post = parent.posts.build
    end

    def update
      if post.update_attributes(params[:post])
        flash[:notice] = 'Item was successfully updated.'
        redirect_to(post) 
      else
        render :action => "edit" 
      end
    end
  end

  <% form_for(item) do |f| %>
    Name: <%= f.text_field :name %>
  <% end %>
  <%= link_to 'Show', item %> |
  <%= link_to 'Back', items_path %>
<commit_msg>Forgot about that comment<commit_after>= automatic_resources

Anyone who's had to deal with nested resources knows that it can get really
messy to have to make everything conditional to support them. Basically it's
just a pain in the ass. If you want to support a nesting structure like the one
in the example below you'll be looking at a big tangled bowl of spaghetti in no
time.

Automatic Resources saves you the trouble. It dynamically defines finder
methods in your controllers and helpers as well as simple named urls that are
100% compatible with the standard ones but produce beautiful nested resource
urls just like you should expect them to.

== Compatible

Automatic Resources doesn't delve into Rails internals or do anything your
grandmother would disapprove of. You can expect it to keep on keepin' on.

== Example

  map.resources :blogs do |blog|
    blog.resources :categories, :has_many => [:posts]
    blog.resources :posts
  end

  class PostsController < ApplicationController
    automatic_resources :blog, :category, :post

    def show
      @blog_name = blog.name if blog?
      @category_name = category.name if category?
      @title = post.title
    end

    def new
      # parent is automatically determined as either blog or category depending
      # on the route we used to get here.
      @post = parent.posts.build
    end

    def update
      if post.update_attributes(params[:post])
        flash[:notice] = 'Item was successfully updated.'
        redirect_to(post) 
      else
        render :action => "edit" 
      end
    end
  end

  <% form_for(item) do |f| %>
    Name: <%= f.text_field :name %>
  <% end %>
  <%= link_to 'Show', item %> |
  <%= link_to 'Back', items_path %>

{'fraction_non_alphanumeric': 0.06969059777711024, 'fraction_numerical': 0.0018023430459597476, 'mean_word_length': 3.220532319391635, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2911226', 'n_tokens_mistral': 961, 'n_tokens_neox': 880, 'n_words': 417}