post '/tags/add' do
  require_login
  current_site.new_tags_string = params[:tags]

  if current_site.valid?
    current_site.save_tags
  else
    flash[:errors] = current_site.errors.first
  end

  redirect request.referer
end

post '/tags/remove' do
  require_login

  DB.transaction {
    params[:tags].each {|tag| current_site.remove_tag Tag[name: tag]}
  }

  redirect request.referer
end

get '/tags/autocomplete/:name.json' do |name|
  Tag.autocomplete(name).collect {|t| t[:name]}.to_json
end