私は今月の収入を前月に比べて単純な月次報告書に電子メールで送付しようとしています。Rails 3アプリケーションの電子メールにコントローラメソッドを含める?
<div class="row">
<div class="twelve columns"><h5>This months income so far is <span style="font-size:1.2em"class="<% if @clinical_income_by_month.first.income >= @clinical_income_by_month.first(:offset => 12).income %>green<% else %>red<% end %> radius label"><%= number_to_currency(@clinical_income_by_month.first.income, :unit => "£", :separator => ".", :delimiter => ",") %></span></h5> <%= @clinical_income_by_month.first.month %> <%= @clinical_income_by_month.first(:offset => 12).year %>'s income was <%= number_to_currency(@clinical_income_by_month.first(:offset => 12).income, :unit => "£", :separator => ".", :delimiter => ",") %>.</div>
</div>
<hr />
<table>
<tr>
<th>Year</th>
<th>Month</th>
<th>Income</th>
</tr>
<% @clinical_income_by_month.each do |c| %>
<tr>
<td><%= c.year %></td>
<td><%= c.month %></td>
<td><%= number_to_currency(c.income, :unit => "£", :separator => ".", :delimiter => ",") %></td>
</tr>
<% end %>
</table>
I:私は、データを持つテーブルのために部分的に持っている
# Clinical income by month report
@clinical_income_by_month = Clinical.select(%q{date_format(transactiondate, '%Y') as year, date_format(transactiondate, '%M') as month, sum(LineBalance) as income})
.where(:payments => 0)
.where('linebalance <> ?', 0)
.where('analysiscode <> ?', 213)
.group(:monthyear)
:
私は(臨床と呼ばれる別のモデルを参照している)私のレポートコントローラにその作業のすべてを持っていますその部分を私の電子メールに引き渡すことができるようにしたい、またはそれが不可能な場合は、最後の収入の価値を示したいと思います。
<%= @clinical_income_by_month.first.income %>
私の電子メールのコードは次のようになります。
Finance Report
================================================
<%= number_to_currency(@clinical_income_by_month.first.income) %>
私は取得していますエラーは次のとおりです。
1.9.2-p318 :009 > UserMailer.finance_report().deliver
ActionView::Template::Error: undefined method `first' for nil:NilClass
from /Users/dannymcclelland/Projects/premvet/app/views/user_mailer/finance_report.text.erb:3:in `_app_views_user_mailer_finance_report_text_erb___4501411113534248604_70358523362460'
私は標準的な方法から値を引いたときにそれが動作:
<%= number_to_currency(Clinical.first.UserID) %>
ただし、私が作成した@clinical_income_by_monthレポートからそれを呼び出します。
何か指摘したいと思います!
を実際に私が「ドン'@click_income_by_vet'がどこで初期化されているのかを見てください。' @click_income_by_month'だけです。ここには間違いがありますか? – alony
うわー、よく目撃された。私は間違った質問を書いたことを示すために更新され、それは獣医でない@ clinical_income_by_monthを靴にするべきです。ありがとう。 – dannymcc
'UserMailer.finance_report()'メソッドでビューに使用するすべての変数を初期化する必要があります – alony