Skip to content

Instantly share code, notes, and snippets.

View aliibrahim's full-sized avatar

Ali Ibrahim aliibrahim

View GitHub Profile
View app\controllers\todo_list_controller.rb
class TodoListsController < ApplicationController
before_action :set_current_user
before_action :set_todo_list, only: %i[show complete_item]
ORDER_OPTIONS = ['created_at', 'updated_at']
def index
sort_order = (params[:asc] == 'false') ? 'ASC' : 'DESC'
@lists = @user.todo_lists.order("#{sort_by_field} #{sort_order}")
aliibrahim / receipt_printer.rb
Created September 19, 2016 16:24
Refactored version of receipt printer
View receipt_printer.rb
class ReceiptPrinter
attr_reader :output, :items
COST = {
'meat' => 5,
'milk' => 3,
'candy' => 1,
View spec_helper.rb
# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'rspec/autorun'
# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}