Skip to content

Commit

Permalink
Merge pull request #68 from daitokai/issue-63/recent-records-on-new-r…
Browse files Browse the repository at this point in the history
…ecord-page

記録画面寂しいし、最近の記録を5件ぐらい表示
  • Loading branch information
LuckOfWise committed Feb 13, 2014
2 parents df88ffd + ebd54ef commit e84c393
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
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"

0 comments on commit e84c393

Please sign in to comment.