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
def self.find( *a, &b ) | |
opts = | |
if Hash === a.last then a.last | |
else | |
a << {} | |
a.last | |
end | |
unless opts.has_key?(:order) | |
opts[:order] = 'name ASC' |
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
# railsext.rb - my collection of rails hacks | |
# | |
# force const_missing to preload these classes - muckery | |
# | |
ActionController | |
ActionController::Base | |
ActiveRecord | |
ActiveRecord::Base |
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
# railsext.rb - my collection of rails hacks | |
# | |
# force const_missing to preload these classes - muckery | |
# | |
ActionController | |
ActionController::Base | |
ActiveRecord | |
ActiveRecord::Base |
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
def copy(content) | |
case RUBY_PLATFORM | |
when /darwin/ | |
return content if `which pbcopy`.strip == '' | |
IO.popen('pbcopy', 'r+') { |clip| clip.puts content } | |
when /linux/ | |
return content if `which xclip`.strip == '' | |
IO.popen('xclip', 'r+') { |clip| clip.puts content } | |
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
def copy(content) | |
case RUBY_PLATFORM | |
when /darwin/ | |
return content if `which pbcopy`.strip == '' | |
IO.popen('pbcopy', 'r+') { |clip| clip.print content.strip } | |
when /linux/ | |
return content if `which xclip`.strip == '' | |
IO.popen('xclip', 'r+') { |clip| clip.print content.strip} | |
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
has_many(:buckets, :dependent => :destroy) do | |
def self.extend_object buckets | |
super | |
ensure | |
buckets.class # hack to know about .each | |
buckets.each do |bucket| | |
bucket.collection = buckets.collection | |
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
class Bucket < ActiveRecord::Base | |
include Sluggable | |
Fu = FileUtils | |
belongs_to :collection | |
collection_reader = instance_method 'collection' | |
define_method('collection') do |*a| | |
@collection ? @collection : collection_reader.bind(self).call(*a) | |
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
has_many :buckets, :dependent => :destroy | |
buckets = instance_method(:buckets) | |
define_method(:buckets) do |*a| | |
@buckets ||= buckets.bind(self).call(*a) | |
@buckets.each{|bucket| bucket.collection = self} | |
@buckets | |
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
def lettuce_report_review | |
allows :student, :studentdemo | |
setup_for_student | |
@number = params[:id] || 1 | |
@disabled = params[:disabled]||params[:readonly]||request.query_string.to_s[%r/disabled|readonly/] | |
@review = @unit.find_lettuce_report_review(:student => @student, :number => @number) | |
unless @review |
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
def lettuce_report | |
allows :student, :studentdemo | |
setup_for_student | |
@report = @unit.find_lettuce_seed_bioassay_report(:student => @student) | |
@questionnaire = @report.questionnaire | |
@questions_and_answers = @student.questions_and_answers_for(@questionnaire, :context => @classroom, :blank => true) | |
if request.post? | |
transaction do |