From eb93591ad15cb6ae4942f08b225fcb0cf3b5613e Mon Sep 17 00:00:00 2001 From: pikesley Date: Fri, 29 Jan 2016 22:09:54 +0000 Subject: [PATCH] Added carbs Now I have another problem :/ --- .../javascripts/carbohydrate_intake.coffee | 3 + .../stylesheets/carbohydrate_intake.scss | 3 + .../carbohydrate_intakes_controller.rb | 11 ++ app/helpers/carbohydrate_intake_helper.rb | 2 + app/views/carbohydrate_intakes/_form.html.erb | 45 +++++++ app/views/carbohydrate_intakes/edit.html.erb | 12 ++ app/views/carbohydrate_intakes/index.html.erb | 3 + app/views/carbohydrate_intakes/new.html.erb | 5 + app/views/carbohydrate_intakes/show.html.erb | 4 + app/views/shared/_nav.html.erb | 1 + app/views/welcome/index.html.erb | 1 + .../carbohydrate_intake_controller_spec.rb | 122 ++++++++++++++++++ spec/controllers/generic_controller_spec.rb | 4 +- .../glucose_measurements_controller_spec.rb | 2 +- .../medication_events_controller_spec.rb | 2 +- spec/factories/carbohydrate_intakes.rb | 4 + .../carbohydrate_intake_helper_spec.rb | 2 + 17 files changed, 221 insertions(+), 5 deletions(-) create mode 100644 app/assets/javascripts/carbohydrate_intake.coffee create mode 100644 app/assets/stylesheets/carbohydrate_intake.scss create mode 100644 app/controllers/carbohydrate_intakes_controller.rb create mode 100644 app/helpers/carbohydrate_intake_helper.rb create mode 100644 app/views/carbohydrate_intakes/_form.html.erb create mode 100644 app/views/carbohydrate_intakes/edit.html.erb create mode 100644 app/views/carbohydrate_intakes/index.html.erb create mode 100644 app/views/carbohydrate_intakes/new.html.erb create mode 100644 app/views/carbohydrate_intakes/show.html.erb create mode 100644 spec/controllers/carbohydrate_intake_controller_spec.rb create mode 100644 spec/helpers/carbohydrate_intake_helper_spec.rb diff --git a/app/assets/javascripts/carbohydrate_intake.coffee b/app/assets/javascripts/carbohydrate_intake.coffee new file mode 100644 index 0000000..24f83d1 --- /dev/null +++ b/app/assets/javascripts/carbohydrate_intake.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/assets/stylesheets/carbohydrate_intake.scss b/app/assets/stylesheets/carbohydrate_intake.scss new file mode 100644 index 0000000..873a786 --- /dev/null +++ b/app/assets/stylesheets/carbohydrate_intake.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the CarbohydrateIntake controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/carbohydrate_intakes_controller.rb b/app/controllers/carbohydrate_intakes_controller.rb new file mode 100644 index 0000000..c922cbe --- /dev/null +++ b/app/controllers/carbohydrate_intakes_controller.rb @@ -0,0 +1,11 @@ +class CarbohydrateIntakesController < GenericController + private + + def metrics_path + carbohydrate_intakes_path + end + + def acceptable_params + params.require(:carbohydrate_intake).permit(:datetime, :weight, :description) + end +end diff --git a/app/helpers/carbohydrate_intake_helper.rb b/app/helpers/carbohydrate_intake_helper.rb new file mode 100644 index 0000000..954b108 --- /dev/null +++ b/app/helpers/carbohydrate_intake_helper.rb @@ -0,0 +1,2 @@ +module CarbohydrateIntakeHelper +end diff --git a/app/views/carbohydrate_intakes/_form.html.erb b/app/views/carbohydrate_intakes/_form.html.erb new file mode 100644 index 0000000..cdbfbaf --- /dev/null +++ b/app/views/carbohydrate_intakes/_form.html.erb @@ -0,0 +1,45 @@ +<%= form_for @metric do |f| %> + + <% if @metric.errors.any? %> +
+

+ <%= pluralize(@metric.errors.count, "error") %> prohibited + this measurement from being saved: +

+ +
+ <% end %> + +

+ <%= f.label :datetime, 'Date and time' %>
+ <%= f.text_field :datetime, id: 'carbohydrate_intake_datetime', class: 'form-control' %> +

+ +

+ <%= f.label :weight %>
+ <%= f.text_field :weight, class: 'form-control' %> +

+ +

+ <%= f.label :description %>
+ <%= f.text_field :description, class: 'form-control' %> +

+ +

+ <%= f.submit class: 'btn btn-success' %> + +

+<% end %> + + diff --git a/app/views/carbohydrate_intakes/edit.html.erb b/app/views/carbohydrate_intakes/edit.html.erb new file mode 100644 index 0000000..29e6bb7 --- /dev/null +++ b/app/views/carbohydrate_intakes/edit.html.erb @@ -0,0 +1,12 @@ +

Carbs Intake

+ +<%= render 'form' %> + +<%= link_to 'Delete', carbohydrate_intake_path(@metric), + class: 'btn btn-warning', + method: :delete, + data: { + confirm: 'Are you sure?' + } %> + +<%= link_to 'Back', carbohydrate_intakes_path, class: 'btn btn-default' %> diff --git a/app/views/carbohydrate_intakes/index.html.erb b/app/views/carbohydrate_intakes/index.html.erb new file mode 100644 index 0000000..44cb4b6 --- /dev/null +++ b/app/views/carbohydrate_intakes/index.html.erb @@ -0,0 +1,3 @@ +<%= render partial: 'shared/index', locals: { + title: 'carbs' +} %> diff --git a/app/views/carbohydrate_intakes/new.html.erb b/app/views/carbohydrate_intakes/new.html.erb new file mode 100644 index 0000000..825db4b --- /dev/null +++ b/app/views/carbohydrate_intakes/new.html.erb @@ -0,0 +1,5 @@ +

New Carbohydrate Intake

+ +<%= render 'form' %> + +<%= link_to 'Back', carbohydrate_intakes_path, class: 'btn btn-default' %> diff --git a/app/views/carbohydrate_intakes/show.html.erb b/app/views/carbohydrate_intakes/show.html.erb new file mode 100644 index 0000000..098307e --- /dev/null +++ b/app/views/carbohydrate_intakes/show.html.erb @@ -0,0 +1,4 @@ +

Datetime: <%= @metric.datetime %>

+

Weight: <%= @metric.value %>

+ +<%= link_to 'Back', carbohydrate_intakes_path %> diff --git a/app/views/shared/_nav.html.erb b/app/views/shared/_nav.html.erb index 57a02fd..e03d123 100644 --- a/app/views/shared/_nav.html.erb +++ b/app/views/shared/_nav.html.erb @@ -16,6 +16,7 @@