0
0
Fork 0

- reordered some urls

- splitted the edit and create template
This commit is contained in:
Gibheer 2011-07-01 10:45:55 +02:00
parent 31e3dc5909
commit 63c0d87b6f
5 changed files with 40 additions and 31 deletions

View File

@ -13,10 +13,27 @@ class Admin < Sinatra::Base
haml :admin_posts
end
get '/post/new' do
@post = Post.new
haml :admin_post_create
end
put '/post' do
@post = Post.new(params[:post])
if @post.save
flash.notice = 'Post saved'
redirect "/admin/post/#{@post.id}"
else
flash.error = 'Error at saving the post'
flash[:errors] = @post.errors
redirect "/admin/post/new"
end
end
get '/post/:id' do
@post = Post.get(params[:id])
if @post
haml :admin_post
haml :admin_post_change
else
flash.warning = "Post with id #{params[:id]} not found!"
redirect './post'
@ -37,28 +54,13 @@ class Admin < Sinatra::Base
flash.warning = 'Error at saving the post!'
flash[:errors] = true
end
haml :admin_post
haml :admin_post_change
else
flash.warning = "Post with id #{params[:id]} not found!"
redirect './post'
end
end
get '/post/new' do
haml :admin_post_new
end
put '/post' do
@post = Post.new(param[:post])
if @post.save
flash.notice = 'Post saved'
else
flash.error = 'Error at saving the post'
flash[:errors] = @post.errors
end
haml :admin_post_new
end
get '/' do
haml :admin_index_no_login
end

View File

@ -0,0 +1,10 @@
-unless @post.errors.nil?
-@post.errors.each do |error|
.error=error
%form{:action => "/admin/post/#{@post.id}", :method => :post}
.fields
=haml :admin_post_edit, :layout => nil
.buttons
%button{:type => :submit}="Update"
%button{:type => :submit, :formmethod => :get,
:formaction => '/admin/post'}="Back"

View File

@ -0,0 +1,11 @@
-if flash[:errors].nil?
-@post.errors.each do |error|
.error=error
%form{:action => "/admin/post", :method => :post}
.fields
%input{:type => :hidden, :name => "_method", :value => :put}=""
=(haml :admin_post_edit, :layout => nil)
.buttons
%button{:type => :submit}="Create"
%button{:type => :submit, :formmethod => :get,
:formaction => '/admin/post'}="Back"

View File

@ -1,7 +1,3 @@
%a{:href => '/admin/post'}="Back"
-if flash[:errors].nil?
-@post.errors.each do |error|
.error=error
%form{:action => "/admin/post/#{@post.id}", :method => :post}
.title
%label{:for => :post_title}="Title"
@ -27,7 +23,3 @@
:class => "post-released-#{@post.released}", :value => 0,
:checked => @post.released, :id => :post_released}
%textarea.content{:name => 'post[content]'}=@post.content
.buttons
%button{:type => :submit}="Update"
%button{:type => :submit, :formmethod => :get,
:formaction => '/admin/post'}="Back"

View File

@ -1,6 +0,0 @@
-@posts.each do |post|
.post
%p.title
%a{:href => "./post/#{post.id}"}=post.title
%span.released{:class => "post-released-#{post.released}"}
%span.written=post.written