Sha256: e0e6a606ac86c57232ee4b643c00822266defbe8a76f646fe9d001c30f288ef6

Contents?: true

Size: 991 Bytes

Versions: 3

Compression:

Stored size: 991 Bytes

Contents

module Sinatra
  
  module SinatraExample
    module Posts
      
      module Helpers
        def posts_path(path = nil)
          "/posts#{path}"
        end
      end
      
      def self.registered(app)
        app.helpers Sinatra::SinatraExample::Posts::Helpers
         
        app.get '/posts' do
          @posts = Post.all
          erb :'posts/index'
        end
        
        app.post '/posts' do
          @post = Post.new params['post']
          if @post.save
            redirect posts_path("/#{@post.id}")
          else
            erb :'posts/new'
          end
        end
        
        app.get '/posts/new' do
          @post = Post.new
          erb :'posts/new'
        end
        
        app.get '/posts/:id' do
          @post = Post.find(params['id'])
          erb :'posts/show'
        end
        
      end # self.registered(app)
      
    end # module Posts
  end # module SinatraExample
  register Sinatra::SinatraExample::Posts
end # module Sinatra

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rmce_uploadr-0.0.3 examples/sinatra/app/posts_controller.rb
rmce_uploadr-0.0.2 examples/sinatra/app/posts_controller.rb
rmce_uploadr-0.0.1 examples/sinatra/app/posts_controller.rb