Skip to content

Instantly share code, notes, and snippets.

class ResultSetsController < ApplicationController
def index
@survey = Survey.find(params[:id]) # should be :survey_id if you want to conform to rails standard.
@quiz = @survey.quiz # try to retrieve quiz from survey, you should not have to load all the result sets to find the right quiz id.
@result_sets = Survey.result_sets.owned_by(result_set_owner)
# Rest of code follows below but requires major refactoring.
end
private
class Programme < AR::Base
has_many :villages
has_many :conversations, though: :villages
end
class Village < AR::Base
has_many :discussions
has_many :conversations, through: :discussions
end
class Change < ActiveRecord::Base
has_many :conversations
validates :name, presence: true
def self.top_ranked(load_conversation=true)
with_rank(load_conversation).order("conversations_rank desc").limit(1)
end
def self.with_rank(load_conversation=true)
class Village < AR::Base
has_many :discussions
has_many :conversations, through: :discussions
has_many :changes, through: :conversations
def top_change
changes.merge Change.top_ranked(false)
end
end
courses.each do |course|
InventoryLineItem.where(course_id: course.id).update_all master_variants[course.id]
end
Shirt:
Color: Red, Blue, Yellow
Pants:
Color: Red, Blue, Yellow
Clothes Bundle:
Color: Red, Blue, Yellow.
class Spree::Variant
def course_with_fallback
course || product.course
end
end
module ApplicationHelper
def edit_create_info_link(model)
model_name = model.class.to_s.underscore
if model.persisted?
link_to 'Edit', { :action => "#{model_name}_info_edit", :id => barn.url, :search_name => params[:search_name], :page => params[:page] }, id: "#{model.url}-info-edit"
else
link_to 'Create', { :action => "new_#{model_name}_info", :id => barn.url, :search_name => params[:search_name], :page => params[:page] }, id: "#{model.url}-info-create"
end
end
end
class Login
has_one :user
end
class User
belongs_to :login
delegate :first_name, :first_name=, to: :login
end
class Product
belongs_to :course
end
class Variant
belongs_to :course
end
class InventoryOrder
def process