Created
April 6, 2010 10:55
-
-
Save Mikr0Tik/357468 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment