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 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 | |
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 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 |
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 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) |
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 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 |
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
courses.each do |course| | |
InventoryLineItem.where(course_id: course.id).update_all master_variants[course.id] | |
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
Shirt: | |
Color: Red, Blue, Yellow | |
Pants: | |
Color: Red, Blue, Yellow | |
Clothes Bundle: | |
Color: Red, Blue, Yellow. |
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 Spree::Variant | |
def course_with_fallback | |
course || product.course | |
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
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 |
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 Login | |
has_one :user | |
end | |
class User | |
belongs_to :login | |
delegate :first_name, :first_name=, to: :login | |
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 Product | |
belongs_to :course | |
end | |
class Variant | |
belongs_to :course | |
end | |
class InventoryOrder | |
def process |