This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Merb::Router.prepare do |r| | |
| r.match("(:path_account)", :account => "(:path_account|:subdomain)") do |stuff| | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Application < Merb::Controller | |
| before :login_required | |
| end | |
| class Foo < Application | |
| end | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| it "allows wrapping of nested routes all having shared argument with PREDEFINED VALUES" do | |
| Merb::Router.prepare do |r| | |
| r.match(/\/?(en|es|fr|be|nl)?/).to(:language => "[1]") do |l| | |
| l.match("/guides/:action/:id").to(:controller => "tour_guides") | |
| end | |
| end | |
| route_to('/se/guides/search/stokholm').should have_route(:controller => 'tour_guides', :action => "search", :id => "stokholm", :language => nil) | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def match(request) | |
| cached_path = request.path | |
| cached_method = request.method | |
| if (/^\/users(?:\/index)?(?:\.([^\/.,;?]+))?$/ =~ cached_path && ((path1 = $1) || true)) && (cached_method == "get") | |
| [0, {:controller => "users", :format => (path1), :action => "index"}] | |
| elsif (/^\/users(?:\.([^\/.,;?]+))?$/ =~ cached_path && ((path1 = $1) || true)) && (cached_method == "post") | |
| [1, {:controller => "users", :format => (path1), :action => "create"}] | |
| elsif (/^\/users\/new(?:\.([^\/.,;?]+))?$/ =~ cached_path && ((path1 = $1) || true)) && (cached_method == "get") | |
| [2, {:controller => "users", :format => (path1), :action => "new"}] | |
| elsif (/^\/users\/one(?:\.([^\/.,;?]+))?$/ =~ cached_path && ((path1 = $1) || true)) && (cached_method == "get") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env ruby | |
| require 'ostruct' | |
| require "rubygems" | |
| require "rbench" | |
| require File.join(File.dirname(__FILE__), '..', 'lib', 'router') | |
| PATH1 = "/users/1" | |
| PATH2 = "/articles/1" | |
| STRING = "/users/1".freeze |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| describe "a resource with extra actions" do | |
| collection = { :one => :get, :two => :post, :three => :put, :four => :delete } | |
| member = { :five => :get, :six => :post, :seven => :put, :eight => :delete } | |
| before(:each) do | |
| Router.prepare do |r| | |
| r.resources :users, :collection => collection, :member => member | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Merb::Router.prepare do |r| | |
| r.domain(":account.domain.com") do |account| | |
| r.resources :users | |
| end | |
| end | |
| # currently on foo.domain.com | |
| url(:users, :account => "foo") # => /users |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Router.prepare do |r| | |
| r.resources :user do |u| | |
| u.resources :comments | |
| end | |
| r.resources :articles do |u| | |
| u.resouces :comments | |
| end | |
| r.resources :comments |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| carl-lerches-mac-pro:router carllerche$ rake specs:old | |
| (in /Users/carllerche/Developer/Source/router) | |
| The default routes | |
| - should match /foo to the Foo controller and index action | |
| - should match /foo/bar to the Foo controller and the bar action | |
| - should match /foo/bar/12 to the Foo controller, the bar action, and id of 12 | |
| Deferred routes | |
| - should match routes based on the incoming params |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Merb::Router.prepare do |r| | |
| r.resources :users do |u| | |
| u.resources :comments | |
| end | |
| end | |
| # --- Will use @comment.id and @comment.user_id | |
| url(:user_comment, @comment) # => /users/123/comments/321 | |
| # --- Knows the order of arguments in the route and assigns values accordingly | |
| url(:user_comment, @comment.user, @comment) # => /users/123/comments/321 |