Skip to content

Instantly share code, notes, and snippets.

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
class Job < ActiveRecord::Base
# there is a jobs_people table on client side
# has_and_belongs_to_many :people # how to workaround this?
end
class Job < ActiveRecord::Base
has_and_belongs_to_many :sources
end
class Person < ActiveRecord::Base
named_scope :job, lambda { |name|
{ :joins => :job, :conditions => { "job.name" => name } }
}
named_scope :car, lambda { |number|
{ :joins => :car, :conditions => { "car.number" => number } }
}
end
def test_should_scope_active
expected = { :conditions => { inactive => false }, :order => 'name asc' }
assert_equal expected, Person.active.proxy_options
end
user_input_date =~ /^[0-9]{8}$/
user_input_date = Date.strptime("#{user_input_date[0..1]}.#{user_input_date[2..3]}.#{user_input_date[4..7]}", "%d.%m.%Y")
/**
* Methods for extending Prototype
*/
var Position = {
/**
* Centers an element against the parent or body
* parent should be display: relative
*/
center: function(elem, parent){
module Foo
def self.included base
include Foo::InstanceMethods
end
module InstanceMethods
def bar
@bar = 'Bar'
end
end
end
# paginator(people_path) is helper method returning html:
# the '\n' have to be wiped out
page << "$$('.paginate').invoke('update', '#{ j(paginator(people_path).gsub(/\n/,'')) }')"
the issue i have: in the js.rjs i have to render a partial '_index',
but i wish i could render a 'index.html.erb',
like page.replace_html 'people', :template => 'index'
(but it ends up in a "Element.update("people", null);", thought the template is not empty)