Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

記録画面寂しいし、最近の記録を5件ぐらい表示 #68

Merged
merged 2 commits into from
Feb 13, 2014
Merged
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
15 changes: 12 additions & 3 deletions app/controllers/records_controller.rb
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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!
Expand Down Expand Up @@ -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
Expand Down
20 changes: 18 additions & 2 deletions app/views/records/new.html.haml
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
%h1 記録する
.row
%h1 記録する
= render 'form'

= render 'form'
.row
%h1 最近の記録
%table.table
%tr
%th 日付
%th 体重
%th コメント
%th 目標まで

- @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"