Skip to content

Instantly share code, notes, and snippets.

@Mikr0Tik
Created April 6, 2010 10:55
Show Gist options
  • Save Mikr0Tik/357468 to your computer and use it in GitHub Desktop.
Save Mikr0Tik/357468 to your computer and use it in GitHub Desktop.
class FiltersController < ApplicationController
def update
if params[:filter]
@filter = ::Filter.find params[:id]
@filter.attributes = params[:filter]
else
method = "add_or_remove_#{find_attribut}"
self.send(method) #if self.respond_to?(method)
return
end
respond_to do |format|
format.js
end
end
private
def find_attribut
%w(people system project status).detect { |attribut| params[attribut] }
end
def add_or_remove_people
add_or_remove_objekt :people, Person.find(params[:people])
end
def add_or_remove_system
add_or_remove_objekt :system, System.find(params[:system])
end
def add_or_remove_objekt attribute, object
@attribute = attribute
@object = object
if @filter.send(@attribute).include?(@object)
@filter.send(@attribute).delete @object
render_remove
else
@filter.send(@attribute) << @object
render_add
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment