Skip to content

Instantly share code, notes, and snippets.

@marclipovsky
marclipovsky / gist:2241307
Created March 29, 2012 18:11
scope creating array rather than activerecord::relation
scope :for_account, lambda { |account|
find_by_sql("SELECT 'tickets'.* FROM 'tickets'
INNER JOIN 'groups' ON 'groups'.'id' = 'tickets'.'group_id'
INNER JOIN 'assignments' ON 'groups'.'id' = 'assignments'.'group_id'
INNER JOIN 'accounts' ON 'accounts'.'id' = 'assignments'.'account_id'
WHERE ('accounts'.'id' = #{account.id})
UNION
SELECT 'tickets'.* FROM 'tickets'
INNER JOIN 'tasks' ON 'tasks'.'ticket_id' = 'tickets'.'id'
INNER JOIN 'accounts' ON 'accounts'.'id' = 'tasks'.'account_id'
<div id="add_default_tasks">
<h2>Default Tasks</h2>
<div class="fields">
<input id="ticket_tasks_attributes_0_name" name="ticket[tasks_attributes][0][name]" size="30" type="text" value="Create Invite" />
<input id="ticket_tasks_attributes_0__destroy" name="ticket[tasks_attributes][0][_destroy]" type="hidden" value="false" /><a href="javascript:void(0)" class="remove_task remove_nested_fields">Remove this task</a>
<input id="ticket_tasks_attributes_0_name" name="ticket[tasks_attributes][0][name]" size="30" type="text" value="Name Tags" />
<input id="ticket_tasks_attributes_0__destroy" name="ticket[tasks_attributes][0][_destroy]" type="hidden" value="false" /><a href="javascript:void(0)" class="remove_task remove_nested_fields">Remove this task</a>
<input id="ticket_tasks_attributes_0_name" name="ticket[tasks_attributes][0][name]" size="30" type="text" value="Giveaways" />
<input id="ticket_tasks_attributes_0__destroy" name="ticket[tasks_attributes][0][_destroy]" type="hidden"
@marclipovsky
marclipovsky / gist:1186408
Created September 1, 2011 15:22
nested_forms creating default tasks from category tasks
<!-- START category.rb -->
class Category < ActiveRecord::Base
has_many :tickets
has_many :tasks
accepts_nested_attributes_for :tasks, :allow_destroy => true, :reject_if => proc { |obj| obj.blank? }
end
<!-- END category.rb -->
<!-- START ticket.rb -->
class Ticket < ActiveRecord::Base
@marclipovsky
marclipovsky / gist:1186122
Created September 1, 2011 13:04
Scopes Causing undefined method `const_defined?'
activemodel (3.0.6) lib/active_model/attribute_methods.rb:367:in `method_missing'
activerecord (3.0.6) lib/active_record/attribute_methods.rb:46:in `method_missing'
activesupport (3.0.6) lib/active_support/dependencies.rb:372:in `local_const_defined?'
activesupport (3.0.6) lib/active_support/dependencies.rb:497:in `load_missing_constant'
activerecord (3.0.6) lib/active_record/relation.rb:98:in `any?'
activerecord (3.0.6) lib/active_record/attribute_methods/read.rb:72:in `any?'
activerecord (3.0.6) lib/active_record/relation.rb:98:in `each'
activerecord (3.0.6) lib/active_record/relation.rb:98:in `any?'
activerecord (3.0.6) lib/active_record/relation.rb:98:in `any?'
activesupport (3.0.6) lib/active_support/dependencies.rb:497:in `load_missing_constant'
class Category < ActiveRecord::Base
has_many :tickets
has_many :tasks, :dependent => :destroy
accepts_nested_attributes_for :tasks, :reject_if => lambda { |a| a[:name].blank? }, :allow_destroy => true
acts_as_tree
has_friendly_id :name, :use_slug => true
scope :parent, where({:parent_id => nil}, {})
scope :children, where({'parent_id > ?', 0}, {})
@marclipovsky
marclipovsky / gist:1185772
Created September 1, 2011 09:14
Stack level too deep
activesupport (3.0.6) lib/active_support/inflector/methods.rb:52:in `underscore'
activesupport (3.0.6) lib/active_support/core_ext/string/inflections.rb:83:in `underscore'
activesupport (3.0.6) lib/active_support/dependencies.rb:482:in `load_missing_constant'
activesupport (3.0.6) lib/active_support/dependencies.rb:183:in `const_missing'
activesupport (3.0.6) lib/active_support/dependencies.rb:181:in `each'
activesupport (3.0.6) lib/active_support/dependencies.rb:181:in `const_missing'
activerecord (3.0.6) lib/active_record/relation.rb:370:in `send'
activerecord (3.0.6) lib/active_record/relation.rb:370:in `method_missing'
activerecord (3.0.6) lib/active_record/relation.rb:125:in `scoping'
activerecord (3.0.6) lib/active_record/relation.rb:370:in `method_missing'
RAILS_ROOT = File.dirname(File.dirname(__FILE__))
20.times do |num|
God.watch do |w|
w.name = "dj-#{num}"
w.group = 'dj'
w.interval = 30.seconds
w.start = "rake -f #{RAILS_ROOT}/Rakefile -I #{RAILS_ROOT} RAILS_ENV=production jobs:work"
w.uid = 'git'