don't cache URL since it persists for drafts too

This commit is contained in:
Sami Samhuri 2015-05-06 23:39:02 -07:00
parent f200158d16
commit f1ca433f62
2 changed files with 10 additions and 7 deletions

View file

@ -77,12 +77,11 @@ class HarpBlog
end end
def url def url
@url ||= if draft?
if draft? "/posts/drafts/#{id}"
"/posts/drafts/#{id}" else
else "/posts/#{time.year}/#{padded_month}/#{slug}"
"/posts/#{time.year}/#{padded_month}/#{slug}" end
end
end end
def slug def slug

View file

@ -186,7 +186,7 @@ get '/posts/drafts/:id' do |id|
end end
end end
# make a draft # make a draft, and optionally publish it immediately
post '/posts/drafts' do post '/posts/drafts' do
unless authenticated?(request.env['HTTP_AUTH']) unless authenticated?(request.env['HTTP_AUTH'])
status 403 status 403
@ -196,6 +196,10 @@ post '/posts/drafts' do
id, title, body, link = @fields.values_at('id', 'title', 'body', 'link') id, title, body, link = @fields.values_at('id', 'title', 'body', 'link')
begin begin
if post = blog.create_post(title, body, link, id: id, draft: true) if post = blog.create_post(title, body, link, id: id, draft: true)
if @fields['publish'] == 'true'
post = blog.publish_post(post)
blog.publish(@fields['env'])
end
url = url_for(post.url) url = url_for(post.url)
status 201 status 201
headers 'Location' => url, 'Content-Type' => 'application/json' headers 'Location' => url, 'Content-Type' => 'application/json'