I'm trying to summarize some of my code right now. While everything went well, I wrote some mixes that I can dynamically add to controllers or models so that everything is done obeying DRY.
But with my Searchform-Helper, I got into a corner in which, right now, I'm a little ignorant.
I have a mixin 'SearchIndexController' that adds the methods needed to search for data in a searchindex table.
After enabling mixin, I can initialize the search actions in the appropriate controller by calling this method:
def init_searchaction(object, name=nil)
singular = object.to_s.classify
plural = singular.pluralize
name = "search_#{singular}".to_sym if name.nil?
unless self.respond_to?(name)
define_method(name) do
success=false
needle = params[:query]
success, x, notice = execute_search("#{singular}", needle)
respond_to do |format|
format.js {
render :update do |page|
page.call "sidx_updateSearchResultContentAtIdTag", "##{plural.downcase} tbody", "#{render x}" if success
page.call "sidx_updateNotice", success, "#{notice}"
page.call "sidx_stopSpinner"
end
}
end
end
else
logger.warn("#{__FILE__}:#{__LINE__}:#{self.to_s}: search-action for '#{self.class.name}' can not be created, it already exists!")
end
end
, , User-Controller. Userform . , , , ... . :
init_searchaction :user
init_searchaction :department
init_searchaction :client, :find_clients
,
search_user
search_department
find_clients
, , . . "init_searchaction", mixin .
... mixins init_searchaction? , #TODO . , ... , , .
- , ? , !