issue #10 fix "add tags to posts"
This commit is contained in:
parent
41a470c4c0
commit
e478a71c32
7
admin.rb
7
admin.rb
|
@ -58,9 +58,12 @@ class Admin < Sinatra::Base
|
|||
@post = Post.get(params[:id])
|
||||
if @post
|
||||
if params[:post].has_key? 'tags'
|
||||
@post.set_tags params[:post].delete('tags')
|
||||
tags = params[:post].delete('tags')
|
||||
end
|
||||
unless @post.update(params[:post])
|
||||
if @post.update(params[:post])
|
||||
@post.set_tags tags
|
||||
@post.save
|
||||
else
|
||||
flash.warning = 'Error at saving the post!'
|
||||
flash[:errors] = true
|
||||
end
|
||||
|
|
|
@ -46,9 +46,6 @@ class Post
|
|||
|
||||
# sets all tags for this post
|
||||
def set_tags new_tags
|
||||
tags = []
|
||||
new_tags.each do |tag_id|
|
||||
tags << Tag.first(:id => tag_id)
|
||||
end
|
||||
self.tags = Tag.all(:id => new_tags)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -39,7 +39,7 @@
|
|||
%option{:value => account.id}=account.username
|
||||
.tags
|
||||
%label{:for => :post_tags}="Tags (#{Tag.all.count})"
|
||||
%select{:name => 'post[tags]', :id => :post_tags, :size => 10, :multiple => true}
|
||||
%select{:name => 'post[tags][]', :id => :post_tags, :size => 10, :multiple => true}
|
||||
- post_tags = @post.tags
|
||||
- Tag.all(:order => [:name.asc]).each do |tag|
|
||||
-if @post.has_tag tag
|
||||
|
|
Loading…
Reference in New Issue