- reordered some urls
- splitted the edit and create template
This commit is contained in:
parent
31e3dc5909
commit
63c0d87b6f
36
admin.rb
36
admin.rb
|
@ -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
|
||||
|
|
|
@ -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"
|
|
@ -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"
|
|
@ -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"
|
|
@ -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
|
Loading…
Reference in New Issue