Skip to content

Instantly share code, notes, and snippets.

@hallison
Created August 6, 2009 16:19
Show Gist options
  • Select an option

  • Save hallison/163401 to your computer and use it in GitHub Desktop.

Select an option

Save hallison/163401 to your computer and use it in GitHub Desktop.

Revisions

  1. hallison revised this gist Sep 18, 2009. 1 changed file with 0 additions and 3 deletions.
    3 changes: 0 additions & 3 deletions config.ru
    Original file line number Diff line number Diff line change
    @@ -1,9 +1,6 @@
    # In rackup file "config.ru"

    require 'rubygems'
    require 'sinatra'
    require 'sinatra/mapping'

    require 'blogware'

    run Sinatra::Application
  2. hallison revised this gist Sep 18, 2009. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion config.ru
    Original file line number Diff line number Diff line change
    @@ -4,6 +4,6 @@ require 'rubygems'
    require 'sinatra'
    require 'sinatra/mapping'

    require 'blogware' # this source is blogware.rb
    require 'blogware'

    run Sinatra::Application
  3. hallison revised this gist Sep 18, 2009. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion config.ru
    Original file line number Diff line number Diff line change
    @@ -4,6 +4,6 @@ require 'rubygems'
    require 'sinatra'
    require 'sinatra/mapping'

    require 'todoapp'
    require 'blogware' # this source is blogware.rb

    run Sinatra::Application
  4. hallison renamed this gist Sep 18, 2009. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  5. hallison revised this gist Sep 18, 2009. 1 changed file with 2 additions and 33 deletions.
    35 changes: 2 additions & 33 deletions sinatra_mapping_example.rb
    Original file line number Diff line number Diff line change
    @@ -3,38 +3,7 @@
    require 'rubygems'
    require 'sinatra'
    require 'sinatra/mapping'
    require 'sinatra/mapping_helpers'

    require 'yourapp'
    require 'todoapp'

    run Sinatra::Applicatoin

    # In Sinatra application "yourapp.rb"

    register Sinatra::Mapping
    helpers Sinatra::MappingHelpers

    mapping :users => "authors",
    :posts => "articles"

    get users_path do
    # URL usage: /authors
    erb :users
    end

    get users_path "/:user_id" do |user_id|
    # URL usage: /authors/7
    erb :user
    end

    get users_path "/:user_id", :posts do |user_id|
    # URL usage: /authors/7/articles
    # In ERB template: link_to "Author Articles", :users, 7, :articles
    erb :posts
    end

    get users_path "/:user_id", :posts, "/:article_id" do |user_id, article_id|
    # URL usage: /authors/7/articles/8
    # In ERB template: link_to "Article", :users, 7, :posts, 8
    erb :post
    end
    run Sinatra::Application
  6. hallison created this gist Aug 6, 2009.
    40 changes: 40 additions & 0 deletions sinatra_mapping_example.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,40 @@
    # In rackup file "config.ru"

    require 'rubygems'
    require 'sinatra'
    require 'sinatra/mapping'
    require 'sinatra/mapping_helpers'

    require 'yourapp'

    run Sinatra::Applicatoin

    # In Sinatra application "yourapp.rb"

    register Sinatra::Mapping
    helpers Sinatra::MappingHelpers

    mapping :users => "authors",
    :posts => "articles"

    get users_path do
    # URL usage: /authors
    erb :users
    end

    get users_path "/:user_id" do |user_id|
    # URL usage: /authors/7
    erb :user
    end

    get users_path "/:user_id", :posts do |user_id|
    # URL usage: /authors/7/articles
    # In ERB template: link_to "Author Articles", :users, 7, :articles
    erb :posts
    end

    get users_path "/:user_id", :posts, "/:article_id" do |user_id, article_id|
    # URL usage: /authors/7/articles/8
    # In ERB template: link_to "Article", :users, 7, :posts, 8
    erb :post
    end