fizx / collapsed_routes

Gem to clean up rails routes

This URL has Read+Write access

fizx (author)
Wed Jul 01 08:41:33 -0700 2009
commit  b15141ebd7ddf9135b45d9469753f6dceaca361f
tree    972122fc9826614b9f47e1346e47c2bcc77204c4
parent  48754acd411e9f2df6d7a924662f8fc3218e41a2
README.rdoc

collapsed_routes

collapsed_routes is a gem to make hierarchical resource routing easier. Here’s an example:

  ActionController::Routing::Routes.draw do |map|
    map.resources :users do |user|
      user.resources :posts do |post|
        post.resources :comments
      end
    end
  end

If you execute:

  require "collapsed_routes"
  CollapsedRoutes.collapsed_routes :users, :posts, :comments

This will generate the following url_helpers:

  def comment_path(comment = @comment)
    user_post_comment_path(comment.post.user, comment.post, comment)
  end

  def edit_comment_path(comment = @comment)
    edit_user_post_comment_path(comment.post.user, comment.post, comment)
  end

  def new_comment_path(post = @post)
    new_user_post_comment_path(post.user, post)
  end

  def comments_path(post = @post)
    user_post_comments_path(post.user, post)
  end

  def comment_url(comment = @comment)
    user_post_comment_url(comment.post.user, comment.post, comment)
  end

  def edit_comment_url(comment = @comment)
    edit_user_post_comment_url(comment.post.user, comment.post, comment)
  end

  def new_comment_url(post = @post)
    new_user_post_comment_url(post.user, post)
  end

  def comments_url(post = @post)
    user_post_comments_url(post.user, post)
  end

  def post_path(post = @post)
    user_post_path(post.user, post)
  end

  def edit_post_path(post = @post)
    edit_user_post_path(post.user, post)
  end

  def new_post_path(user = @user)
    new_user_post_path(user)
  end

  def posts_path(user = @user)
    user_posts_path(user)
  end

  def post_url(post = @post)
    user_post_url(post.user, post)
  end

  def edit_post_url(post = @post)
    edit_user_post_url(post.user, post)
  end

  def new_post_url(user = @user)
    new_user_post_url(user)
  end

  def posts_url(user = @user)
    user_posts_url(user)
  end

Copyright

Copyright © 2009 Kyle Maxwell. See LICENSE for details.