Skip to content

Instantly share code, notes, and snippets.

@paul
Created October 27, 2011 02:21
Show Gist options
  • Save paul/1318620 to your computer and use it in GitHub Desktop.
Save paul/1318620 to your computer and use it in GitHub Desktop.

Desired URLs:

/accounts/rando-inc   # edit, update (normal "edit" function provided at whats usually "show") 
  /tokens             # new, create, destroy (normal crud)
  /billing            # edit, update         (singleton crud)

Attempt using scopes and macros:

scope '/accounts/:permalink',
      :as => :account,
      :controller => :accounts,
      :constraints => { :permalink => PERMALINK_REGEX } do

    get '/', :action => :edit, :as => :edit
    put '/', :action => :update

    scope '/:permalink',
          :controller => :authentication_tokens,
          :as => :token do
      get :index
      post :create
      delete :destroy
    end

end
# Accomplishes URLs using #match
match '/accounts/:permalink' => 'accounts#edit',
:via => :get,
:as => 'edit_account',
:constraints => { :permalink => PERMALINK_REGEX }
match '/accounts/:permalink' => 'accounts#update',
:via => :put,
:as => 'edit_account',
:constraints => { :permalink => PERMALINK_REGEX }
match '/accounts/:permalink/tokens/new' => 'authentication_tokens#new',
:via => :get,
:as => 'new_tokens',
:constraints => { :permalink => PERMALINK_REGEX }
match '/accounts/:permalink/tokens' => 'authentication_tokens#create',
:via => :post,
:as => 'tokens',
:constraints => { :permalink => PERMALINK_REGEX }
match '/accounts/:permalink/tokens' => 'authentication_tokens#destroy',
:via => :delete,
:as => 'token',
:constraints => { :permalink => PERMALINK_REGEX }
match '/accounts/:permalink/billing' => 'account_billing#edit',
:via => :get,
:as => 'account_billing',
:constraints => { :permalink => PERMALINK_REGEX }
match '/accounts/:permalink/billing' => 'account_billing#update',
:via => :put,
:as => 'account_billing',
:constraints => { :permalink => PERMALINK_REGEX }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment