質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.47%
Ruby

Rubyはプログラミング言語のひとつで、オープンソース、オブジェクト指向のプログラミング開発に対応しています。

Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Q&A

解決済

1回答

176閲覧

Railsでインスタンス変数をviewで読み取れないのですが原因がわからずに困っております。

koume

総合スコア458

Ruby

Rubyはプログラミング言語のひとつで、オープンソース、オブジェクト指向のプログラミング開発に対応しています。

Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

0グッド

0クリップ

投稿2018/03/26 07:55

Rails5.1.3でWebアプリケーション制作の勉強をしています。
経理関係のデータを表示させたくて作成しましたが、コントローラ側のインスタンス変数をviewで読み取れません。
他の所では読み取れていますがこのmonth_marginメソッドのところだけ読み取れないのです。
エラーも発生していません。ページ自体の表示はできていますが、のインスタンス編数に代入した数値がないためか
データの部分が空欄なのです。単純なコードですが下記になります。

records_controller def month_margim margin = Margin.find(1) @year = margin.year @month = margin.month commission = Commission.find_by(pay_bank: "振込") @bank_name = commission.bank_name @fee_low = commission.fee_low @fee_high = commission.fee_high if margin.year == 2018 @check_year = Eighteen @last_check_year = Seventeen render action: 'check_margin' end end def check_margin @margin_c_low = @check_year.where("0 < m_1 < 30000").count @margin_s_low = @check_year.where("0 < pt_special_2 >= 30000").count @margin_c_high = @check_year.where("m_1 < 30000").count @margin_s_high = @check_year.where("pt_special_2 >= 30000").count end
month_margin.html.erb <% @title = '年、月 別 振込み手数料' %> <h1><%= @title %></h1> <% if @unsub == 0 %> <h2><%= @month %> 月 の振込みはありません。</h2> <% else %> <div class="table-wrapper"> <table class="attributes"> <tr><th colspan="3"><strong><%= @year %>年 <%= @month %>月 </strong></th></tr> </table> <table class="listing"> <tr> <th>銀行名</th> <th>振込み年</th> <th>振込み月</th> <th>3万円未満人数</th> <th>3万円以上人数</th> <th>3万円未満手数料</th> <th>3万円以上手数料</th> <th><%= @momth %> 月振込み手数料合計</th> <th><%= @month %> 月振込み事務手数料</th> </tr> <tr> <td><%= @bank_name %></td> <td><%= @year %> 年</td> <td><%= @month %> 月</td> <td><%= @margin_subtotal %> 人</td> <td><%= @margin_total %> 人</td> <td>¥ <%= number_with_delimiter(@low_margin) %></td> <td>¥ <%= number_with_delimiter(@high_margin) %></td> <td>¥ <%= number_with_delimiter(@total) %></td> <td>¥ <%= number_with_delimiter(@margin_month) %></td> </tr> </table> </div> <% end %> <div class="table-wrapper"> <div class="links"> <%= link_to '検索ページへ', :edit_admin_margin %> </div> <div class="links"> <%= link_to 'トップ画面へ戻る', :admin_root %> </div> </div>

このようになっています。インスタンス変数が全く反映されないのです。何が原因かわからずに困っております。
どなたか教えていただけないでしょうか?宜しくお願いします。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

RecordsController#month_marginからRecordsController#check_marginを呼んでいないので、check_marginの中身は実行されません。

投稿2018/03/26 08:02

maisumakun

総合スコア145186

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

koume

2018/03/26 08:06

回答ありがとうございます。check_margin以外の@monthなども表示されないのですがcheck_marginが読みとれていないのと関係あるのでしょうか?
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.47%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問