show a single post
This commit is contained in:
parent
1bd4158b17
commit
4ce3f643dd
|
@ -11,4 +11,8 @@ class Post
|
|||
|
||||
belongs_to :account
|
||||
has n, :comments
|
||||
|
||||
def self.get_released id
|
||||
first(:id => id, :released => true)
|
||||
end
|
||||
end
|
||||
|
|
12
page.rb
12
page.rb
|
@ -1,12 +1,24 @@
|
|||
class Blog < Sinatra::Base
|
||||
set $settings
|
||||
register Sinatra::CompassSupport
|
||||
use Rack::Session::Pool, :expire_after => 1800
|
||||
use Rack::Flash, :accessorize => [:error, :warning, :notice]
|
||||
|
||||
get '/' do
|
||||
@posts = Post.all(:released => true, :order => [:written.desc])
|
||||
haml :index
|
||||
end
|
||||
|
||||
get '/post/:id' do
|
||||
@post = Post.get_released(params[:id])
|
||||
if @post.nil?
|
||||
flash.warning = 'Post not found!'
|
||||
redirect '/'
|
||||
else
|
||||
haml :post_single
|
||||
end
|
||||
end
|
||||
|
||||
get '/stylesheet.css' do
|
||||
scss :stylesheet
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue