Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/assets/javascripts/app.dose.coffee
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# $(document).on "page:change", ->
# alert("dibbity doo")
# Indeed!
2 changes: 2 additions & 0 deletions app/assets/stylesheets/styles.css.sass
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,5 @@
.title
h1
font-weight: normal

// The downside of using CSS libraries is that you use them by putting HTML classes all over the place, resulting in not-very-DRY code. The advantage of SASS is that it gives you tools to circumvent all that. For instance: could you use SASS to say, "make every div an input-field" instead of having to write <div class="input-field"> a zillion times?
2 changes: 2 additions & 0 deletions app/controllers/animals_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def create
@animal.save!
rescue ActiveRecord::RecordInvalid
set_flash
# Neat!
redirect_to new_animal_path
else
redirect_to @animal
Expand All @@ -28,6 +29,7 @@ def create
def show
@doses = @animal.doses
@doses = @doses.order("#{params[:sort_by]} #{params[:order_by]}").joins(:drug, :user)
# Bonus points for joins!
end

def edit
Expand Down
6 changes: 5 additions & 1 deletion app/controllers/doses_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
class DosesController < ApplicationController
before_action :set_animal, only: [:new, :create]
before_action :authenticate_user!
# You have this before_action in most of your controllers, so I'd just do it once in your application controller; then use skip_before_action where necessary.
before_action :set_dose, only: [:destroy, :show]
before_action :get_animal, only: [:destroy, :show]

Expand All @@ -12,20 +13,23 @@ def create
begin
@dose = @animal.doses.new(drug_id: params[:dose]["drug_id"], user: current_user)
@dose.save!
# If you're doing a .save! right after a .new!, you may as well do it in one line with .create!
rescue ActiveRecord::RecordInvalid
flash[:alert] = @dose.errors.full_messages.first
redirect_to new_animal_dose_path(@animal)
else
redirect_to @dose
end
# I know we talked about this, but was there a reason you're using begin/rescue here instead of if @dose.save... else? That follows convention a bit better.
end

def index
@doses = Dose.order("#{params[:sort_by]} #{params[:order_by]}").joins(:drug,:user, :animal)
@doses = Dose.order("#{params[:sort_by]} #{params[:order_by]}").joins(:drug, :user, :animal)
end

def show
@dose = Dose.find(params[:id])
#set_dose
@animal = @dose.animal
end

Expand Down
2 changes: 2 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ def toggle_order(order_direction)
def doses_link(caption, sort_by = nil)
sort_by ||= caption.downcase
default_order_by = 'asc'
# Personal preference, but when lines start getting longlike this I'd break it into a series of if/else
order_by = params[:sort_by]==sort_by ? toggle_order(params[:order_by]) : default_order_by
link_to caption, doses_path(:sort_by => sort_by, :order_by => order_by)
end
Expand All @@ -19,3 +20,4 @@ def animal_doses_link(caption, sort_by = nil)
end

# TODO: combine above two helper methods
# Good idea! Sounds like a fun challenge.
4 changes: 3 additions & 1 deletion app/models/animal.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
class Animal < ActiveRecord::Base
has_many :doses
has_many :drugs, through: :doses, dependent: :destroy
validates :species, inclusion: { in: ['cat','dog']}
# validates :species, inclusion: { in: ['cat','dog']}
validates :species, inclusion: { in: %w"cat dog"}
# You could save two whole characters!
validates :weight, :name, presence: true
end
3 changes: 3 additions & 0 deletions app/models/dose.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ def calculate_dosage
def restrictions
if self.drug
@restriction = self.drug.restrictions
# This variable has a singular name, but seems to contain a collection?
errors.add(:restriction, "- this drug is for #{@restriction}s only") if
!@restriction.blank? and @restriction != self.animal.species
# Interesting syntax! I might split this up into multiple lines too
# The whole 5-line-method thing shouldn't come at the expense of readability!
end
end
end
1 change: 1 addition & 0 deletions app/models/role.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ class Role < ActiveRecord::Base
:allow_nil => true

scopify
# wat
end
1 change: 1 addition & 0 deletions app/views/animals/_cat.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<!-- Holy cow. In the "real world", I probably would have just turned this into a GIF. But cool nonetheless! -->
<svg class='animal-icon' height="99.114738" id="Capa_1" inkscape:version="0.91 r13725" sodipodi:docname="cat.svg" version="1.1" viewBox="0 0 126.14946 99.114738" width="126.14946" x="0px" xml:space="preserve" xmlns:cc="http://creativecommons.org/ns#"
xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" y="0px">
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
devise_for :users
root to: 'home#index'

# These should just be included in the doses resource.
get 'new', to: 'home#new'
post 'new', to: 'home#create'
get 'show', to: 'home#show'
Expand Down
9 changes: 9 additions & 0 deletions db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@
Animal.create(name: 'Yuki', weight: 13, species: 'cat')
Animal.create(name: 'Kiwi', weight: 10, species: 'cat')

# You can use AR's bulk creation method as well:
=begin
Animal.create([
{name: 'Addy', weight: 28, species: 'dog'},
{name: 'Duma', weight: 42, species: 'dog'},
...
])
=end

Drug.create(name: 'Morphine', dosing: 0.3, route: 'IM or SC', concentration: '15 mg/ml', notes: 'Can give up to 1mg/kg with a 50mg maximum dose', restrictions: 'dog')
Drug.create(name: 'Acepromazine', dosing: 0.12, route: 'IM or SC', concentration: '1 mg/ml', notes: 'Causes vomiting. To dilute Ace 10mg/ml draw up to 0.1cc Ace with 1cc NaCl')
Drug.create(name: 'Ketamine', dosing: 0.13, route: 'IV', concentration: '100 mg/ml')
Expand Down