github
Advanced Search
  • Home
  • Pricing and Signup
  • Explore GitHub
  • Blog
  • Login

ryanb / static_actions

  • Admin
  • Watch Unwatch
  • Fork
  • Your Fork
  • Pull Request
  • Download Source
    • 42
    • 2
  • Source
  • Commits
  • Network (2)
  • Issues (2)
  • Downloads (0)
  • Wiki (1)
  • Graphs
  • Branch: master

click here to add a description

click here to add a homepage

  • Branches (1)
    • master ✓
  • Tags (0)
Sending Request…
Enable Donations

Pledgie Donations

Once activated, we'll place the following badge in your repository's detail box:
Pledgie_example
This service is courtesy of Pledgie.

Rails plugin to quickly make named routes for non-RESTful actions. — Read more

  cancel

  cancel
  • Private
  • Read-Only
  • HTTP Read-Only

This URL has Read+Write access

adding documentation for root methods 
Ryan Bates (author)
Thu Apr 03 11:58:15 -0700 2008
commit  04f723450d115c8e42db18b8a493e0556b18e3da
tree    c128011fd708003b212dc874c64b45f09e218063
parent  061cdf2c98a6ba6fb0c537e11f29268741135bff
static_actions /
name age
history
message
file .gitignore Thu Apr 03 10:09:47 -0700 2008 initial import [Ryan Bates]
file LICENSE Thu Apr 03 10:09:47 -0700 2008 initial import [Ryan Bates]
file README Thu Apr 03 11:58:15 -0700 2008 adding documentation for root methods [Ryan Bates]
file Rakefile Thu Apr 03 10:09:47 -0700 2008 initial import [Ryan Bates]
file init.rb Thu Apr 03 10:09:47 -0700 2008 initial import [Ryan Bates]
file install.rb Thu Apr 03 10:09:47 -0700 2008 initial import [Ryan Bates]
directory lib/ Thu Apr 03 11:55:25 -0700 2008 adding root static action methods to remove the... [Ryan Bates]
directory spec/ Thu Apr 03 11:55:25 -0700 2008 adding root static action methods to remove the... [Ryan Bates]
directory tasks/ Thu Apr 03 10:09:47 -0700 2008 initial import [Ryan Bates]
file uninstall.rb Thu Apr 03 10:09:47 -0700 2008 initial import [Ryan Bates]
README
Static Actions
==============

This plugin will allow you to quickly create non-RESTful named routes using "map.static_actions". This way you can truly 
get rid of that generic ":controller/:action" route.


Installation
------------

If you are running edge rails you can install the plugin straight from the repository:

  script/plugin install git://github.com/ryanb/static_actions.git

Otherwise you can install it with this command:

  git clone --depth=1 git://github.com/ryanb/static_actions.git vendor/plugins/static_actions


Instructions
------------

Let's say you have a controller called "about" which has "index", "privacy", and "license" actions. This is a 
non-RESTful controller and usually requires the generic ":controller/:action" route. Instead we will use this plugin's 
static_actions method to generate named routes!

  map.static_actions :about, [:index, :privacy, :license]

That is the same as doing this.

  map.about_index 'about', :controller => 'about', :action => 'index'
  map.about_privacy 'about/privacy', :controller => 'about', :action => 'privacy'
  map.about_license 'about/license', :controller => 'about', :action => 'license'

It also includes a with_format named route for each action.

  map.about_index_with_format 'about.:format', :controller => 'about', :action => 'index'
  map.about_privacy_with_format 'about/privacy.:format', :controller => 'about', :action => 'privacy'
  map.about_license_with_format 'about/license.:format', :controller => 'about', :action => 'license'

Now you have 6 named routes you can use in your view.

  <%= link_to "Privacy", about_privacy_path %>
  <%= link_to "License PDF", about_license_with_format_path(:pdf) %>

If you just have a single action, you can use the singular static_action method which doesn't take an array.
  
  map.static_action :about, :privacy


If you don't want the controller name to be in the named route or path, you can prefix the method with "root_".

  map.root_static_actions :about, [:index, :privacy, :license]
  
This will generate the following routes.
  
  map.root :controller => 'about'
  map.privacy 'privacy', :controller => 'about', :action => 'privacy'
  map.license 'license', :controller => 'about', :action => 'license'
  map.privacy_with_format 'privacy.:format', :controller => 'about', :action => 'privacy'
  map.license_with_format 'license.:format', :controller => 'about', :action => 'license'

Happy routing.

---

Copyright (c) 2008 Ryan Bates, released under the MIT license
Blog | Support | Training | Contact | API | Status | Twitter | Help | Security
© 2010 GitHub Inc. All rights reserved. | Terms of Service | Privacy Policy
Powered by the Dedicated Servers and
Cloud Computing of Rackspace Hosting®
Dedicated Server