0
0
Fork 0

issue #10 fix "add tags to posts"

This commit is contained in:
Gibheer 2011-09-28 15:07:05 +02:00
parent 41a470c4c0
commit e478a71c32
3 changed files with 7 additions and 7 deletions

View File

@ -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

View File

@ -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

View File

@ -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