From cc5a59769f53774f432aebc978e385e478b3c24d Mon Sep 17 00:00:00 2001 From: Tomohiko Himura Date: Tue, 11 Feb 2014 23:55:10 +0900 Subject: [PATCH 1/2] =?UTF-8?q?=E8=A8=98=E9=8C=B2=E7=94=BB=E9=9D=A2?= =?UTF-8?q?=E5=AF=82=E3=81=97=E3=81=84=E3=81=97=E3=80=81=E6=9C=80=E8=BF=91?= =?UTF-8?q?=E3=81=AE=E8=A8=98=E9=8C=B2=E3=82=925=E4=BB=B6=E3=81=90?= =?UTF-8?q?=E3=82=89=E3=81=84=E8=A1=A8=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #63 --- app/controllers/records_controller.rb | 15 ++++++++++++--- app/views/records/new.html.haml | 14 ++++++++++++++ 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/app/controllers/records_controller.rb b/app/controllers/records_controller.rb index a32d0b4..17d0363 100644 --- a/app/controllers/records_controller.rb +++ b/app/controllers/records_controller.rb @@ -1,15 +1,16 @@ class RecordsController < ApplicationController before_action :authenticate_user! before_action :set_record, only: [:edit, :update, :destroy] + before_action :set_records, only: [:index] + before_action :set_recent_records, only: [:new, :create] # GET /records def index - @records = current_user.records.order(target_date: :desc) end # GET /records/new def new - @record = current_user.records.build + @record = @records.build end # GET /records/1/edit @@ -18,7 +19,7 @@ def edit # POST /records def create - @record = current_user.records.build(record_params) + @record = @records.build(record_params) @record.subscribe(@service) if @record.save if current_user.update_second_step! @@ -48,6 +49,14 @@ def destroy private # Use callbacks to share common setup or constraints between actions. + def set_records + @records = current_user.records.order(target_date: :desc) + end + + def set_recent_records + @records = set_records.limit(5) + end + def set_record @record = current_user.records.find(params[:id]) end diff --git a/app/views/records/new.html.haml b/app/views/records/new.html.haml index 3b0fb06..060217d 100644 --- a/app/views/records/new.html.haml +++ b/app/views/records/new.html.haml @@ -1,3 +1,17 @@ %h1 記録する +%table.table + %tr + %th 日付 + %th 体重 + %th コメント + %th 目標まで + + - @records.reverse_each do |record| + %tr + %td=l record.target_date + %td= show_weight record.weight + %td= record.comment + %td= "あと#{show_weight record.to_goal}kg" + = render 'form' From ebd54ef0022fc22b29542e74675adb1dee07b569 Mon Sep 17 00:00:00 2001 From: Tomohiko Himura Date: Thu, 13 Feb 2014 02:10:00 +0900 Subject: [PATCH 2/2] =?UTF-8?q?=E6=9C=80=E8=BF=91=E3=81=AE=E8=A8=98?= =?UTF-8?q?=E9=8C=B2=E3=82=92=E4=B8=8B=E3=81=AB=E3=81=97=E3=81=A6=E3=81=BF?= =?UTF-8?q?=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/records/new.html.haml | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/app/views/records/new.html.haml b/app/views/records/new.html.haml index 060217d..71f279f 100644 --- a/app/views/records/new.html.haml +++ b/app/views/records/new.html.haml @@ -1,17 +1,19 @@ -%h1 記録する +.row + %h1 記録する + = render 'form' -%table.table - %tr - %th 日付 - %th 体重 - %th コメント - %th 目標まで - - - @records.reverse_each do |record| +.row + %h1 最近の記録 + %table.table %tr - %td=l record.target_date - %td= show_weight record.weight - %td= record.comment - %td= "あと#{show_weight record.to_goal}kg" + %th 日付 + %th 体重 + %th コメント + %th 目標まで -= render 'form' + - @records.each do |record| + %tr + %td=l record.target_date + %td= show_weight record.weight + %td= record.comment + %td= "あと#{show_weight record.to_goal}kg"