家計簿アプリ作成中です。各カラムの合計値を算出したい。
ruby(ruby on rails)で家計簿システムを作っています。
カレンダーのような表を出していまして、『電気代』や『ガス代』などの項目の下に各金額のカラムを出しているのですが、
各金額カラムの合計値を算出する機能を実装中なのですが、1日目のカラムの数値の合計しか拾うことができません。
【ユーザーコントローラ】 def show @household_account_book = @user.household_account_books.find_by(worked_on: @first_day..@last_day) end 【show画面のhtmlファイル】 <% provide(:title, @user.name) %> <div> <table class="table table-bordered table-condensed user-table"> <tr> <td>名前:<%= @user.name %></td> </tr> </table> </div> <div class="btn-users-show"> <%= link_to "⇦ 前月へ", user_path(date: @first_day.prev_month), class: "btn btn-info" %> <%= link_to "1ヶ月の家計簿編集へ", household_account_books_edit_one_month_user_path(date: @first_day), class: "btn btn-success" %> <%= link_to "次月へ ⇨", user_path(date: @first_day.next_month), class: "btn btn-info" %> </div> <div> <table class="table table-bordered table-condensed table-hover" id="table-attendances"> <thead> <tr> <th>日付</th> <th>曜日</th> <% if @household_account_book.fixed_cost.present? %> <th><%= @household_account_book.fixed_cost %></th> <% end %> <% if @household_account_book.fixed_cost_1.present? %> <th><%= @household_account_book.fixed_cost_1 %></th> <% end %> <% if @household_account_book.fixed_cost_2.present? %> <th><%= @household_account_book.fixed_cost_2 %></th> <% end %> <% if @household_account_book.fixed_cost_3.present? %> <th><%= @household_account_book.fixed_cost_3 %></th> <% end %> <% if @household_account_book.fixed_cost_4.present? %> <th><%= @household_account_book.fixed_cost_4 %></th> <% end %> <% if @household_account_book.fixed_cost_5.present? %> <th><%= @household_account_book.fixed_cost_5 %></th> <% end %> <% if @household_account_book.fixed_cost_6.present? %> <th><%= @household_account_book.fixed_cost_6 %></th> <% end %> <% if @household_account_book.fixed_cost_7.present? %> <th><%= @household_account_book.fixed_cost_7 %></th> <% end %> <% if @household_account_book.fixed_cost_8.present? %> <th><%= @household_account_book.fixed_cost_8 %></th> <% end %> <% if @household_account_book.fixed_cost_9.present? %> <th><%= @household_account_book.fixed_cost_9 %></th> <% end %> <% if @household_account_book.fixed_cost_10.present? %> <th><%= @household_account_book.fixed_cost_10 %></th> <% end %> <% if @household_account_book.fixed_cost_11.present? %> <th><%= @household_account_book.fixed_cost_11 %></th> <% end %> <% if @household_account_book.fixed_cost_12.present? %> <th><%= @household_account_book.fixed_cost_12 %></th> <% end %> <% if @household_account_book.fixed_cost_13.present? %> <th><%= @household_account_book.fixed_cost_13 %></th> <% end %> <% if @household_account_book.fixed_cost_14.present? %> <th><%= @household_account_book.fixed_cost_14 %></th> <% end %> <th>備考</th> </tr> </thead> <tbody> <!--この@household_account_booksは、application.html.erbのset_one_monthに定義されている--> <% @household_account_books.each do |day| %> <tr> <td><%= l(day.worked_on, format: :short) %></td> <td><%= $days_of_the_week[day.worked_on.wday] %></td> <% if @household_account_book.fixed_cost.present? %> <td><%= day.fixed_n %></td> <% end %> <% if @household_account_book.fixed_cost_1.present? %> <td><%= day.fixed_n_1 %></td> <% end %> <% if @household_account_book.fixed_cost_2.present? %> <td><%= day.fixed_n_2 %></td> <% end %> <% if @household_account_book.fixed_cost_3.present? %> <td><%= day.fixed_n_3 %></td> <% end %> <% if @household_account_book.fixed_cost_4.present? %> <td><%= day.fixed_n_4 %></td> <% end %> <% if @household_account_book.fixed_cost_5.present? %> <td><%= day.fixed_n_5 %></td> <% end %> <% if @household_account_book.fixed_cost_6.present? %> <td><%= day.fixed_n_6 %></td> <% end %> <% if @household_account_book.fixed_cost_7.present? %> <td><%= day.fixed_n_7 %></td> <% end %> <% if @household_account_book.fixed_cost_8.present? %> <td><%= day.fixed_n_8 %></td> <% end %> <% if @household_account_book.fixed_cost_9.present? %> <td><%= day.fixed_n_9 %></td> <% end %> <% if @household_account_book.fixed_cost_10.present? %> <td><%= day.fixed_n_10 %></td> <% end %> <% if @household_account_book.fixed_cost_11.present? %> <td><%= day.fixed_n_11 %></td> <% end %> <% if @household_account_book.fixed_cost_12.present? %> <td><%= day.fixed_n_12 %></td> <% end %> <% if @household_account_book.fixed_cost_13.present? %> <td><%= day.fixed_n_13 %></td> <% end %> <% if @household_account_book.fixed_cost_14.present? %> <td><%= day.fixed_n_14 %></td> <% end %> <% if @household_account_book.fixed_cost_15.present? %> <td><%= day.fixed_n_15 %></td> <% end %> <td><%= day.note %></td> </tr> <% end %> </tbody> </table> </div> <div> <table class="table table-bordered table-condensed table-hover" id="table-attendances"> <tfoot> <tr> <td><%= "合計" %></td> <% @array = @household_account_book.fixed_n.to_i + @household_account_book.fixed_n_1.to_i + @household_account_book.fixed_n_2.to_i + @household_account_book.fixed_n_3.to_i %> <td><%= "#{@array} 円" %></td> </tr> </tfoot> </table> </div>
試したこと
ユーザーコントローラのshowアクションにfind_byで@first_day..@last_dayまでの日にちのカラムのデータを取ろうとするも変化なし。
ご教授下さい。よろしくお願い致します。
補足情報(FW/ツールのバージョンなど)
ここにより詳細な情報を記載してください。