<div dir="ltr"><span style="font-size:12.8px">@Duncan:</span><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">"Is there a reason that ReportCards need to be saved to the database? Would it make sense to instead generate them 'on-demand' based on the data from ReportStats?"</span></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">I had the same thought, but am told that there is a 99% chance our users will want to see these Report Cards in the web app at some point, so makes sense to just make active record objects out of them, so they can be scoped old to new, new to old, etc. Good thought, though, I was leaning the same way initially.</span></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">@Toby:</span></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">You are awesome, your advice got me going in the right direction. I am now at:</span></div><div><span style="font-size:12.8px"><br></span></div><div><pre style="color:rgb(0,0,0)">r.assign_attributes(@newest_stat.attributes)
ActiveModel::MassAssignmentSecurity::Error: Can't mass-assign protected attributes: id, created_at, updated_at</pre><pre style="color:rgb(0,0,0)"><br></pre><pre style="color:rgb(0,0,0)">Just got that error though, havent even started looking up how to fix it yet but Im sure Ill come up with something! </pre><pre style="color:rgb(0,0,0)">Maybe make a new object and strip those from it before calling .attrributes or stripping them from Report Stat first.</pre><div><span style="font-size:12.8px"><br></span></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Mar 8, 2017 at 9:12 AM, Toby Privett <span dir="ltr"><<a href="mailto:tobyprivett@gmail.com" target="_blank">tobyprivett@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Correction: "<span style="color:rgb(33,33,33)">I think you are looking for *something that can iterate*"</span></div><div class="HOEnZb"><div class="h5"><br><div class="gmail_quote"><div dir="ltr">On Wed, 8 Mar 2017 at 14:10 Toby Privett <<a href="mailto:tobyprivett@gmail.com" target="_blank">tobyprivett@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">#assign_attributes expects a hash <a href="http://apidock.com/rails/v4.2.7/ActiveRecord/AttributeAssignment/assign_attributes" target="_blank">http://apidock.com/rails/<wbr>v4.2.7/ActiveRecord/<wbr>AttributeAssignment/assign_<wbr>attributes</a><div><br></div><div>I think you are looking for an iterator</div><div><span style="color:rgb(33,33,33)">e.g. @newest_stat.</span><span style="color:rgb(33,33,33)">attributes </span><br></div><div><span style="color:rgb(33,33,33)"><br></span></div><div><span style="color:rgb(33,33,33)">Hope that helps</span></div></div><br><div class="gmail_quote"><div dir="ltr">On Wed, 8 Mar 2017 at 14:01 Jesse Waites <<a href="mailto:jesse.waites@gmail.com" target="_blank">jesse.waites@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class="m_-5536817573555623173gmail_msg">Hi all--<div class="m_-5536817573555623173gmail_msg"><br class="m_-5536817573555623173gmail_msg"></div><div class="m_-5536817573555623173gmail_msg">I have been tasked with building a report card feature. The end goal of this is that the user gets a monthly email with various statistics (Users logged in, Sites activated, things like hat)</div><div class="m_-5536817573555623173gmail_msg"><br class="m_-5536817573555623173gmail_msg"></div><div class="m_-5536817573555623173gmail_msg">I have settled on Report Stat model and Report Card models. One a month, Report Stat will run and save that data. I take the last 2 report stats (or any 2 report stats, really - thats why I built it this way) and generate the Report Card.</div><div class="m_-5536817573555623173gmail_msg"><br class="m_-5536817573555623173gmail_msg"></div><div class="m_-5536817573555623173gmail_msg">The thing is, most of the data from the Report Card will be the same data from the most recent Report Stat. The users_logged_in from the most recent Report Stat scan will be the number of users_logged_in in the Report Card. There are a few instances where I will want a percentage increase or decrease between Report Stats, I have a integer column ready for that and will just perform simple math on :users_logged_in between my various time frames via various Report Stats.</div><div class="m_-5536817573555623173gmail_msg"><br class="m_-5536817573555623173gmail_msg"></div><div class="m_-5536817573555623173gmail_msg">My issue is, how can I most easily transplant the data from ReportStat into the ReportCard. I could so it manually column by column but that seems like the wrong way to do it, I want to do it programmatically. The columns and datatypes are all the same.</div><div class="m_-5536817573555623173gmail_msg"><br class="m_-5536817573555623173gmail_msg"></div><div class="m_-5536817573555623173gmail_msg">At the end of the day, I think I'd like to be able to do ReportCard.create(:user_id => <a href="http://current_user.id" class="m_-5536817573555623173gmail_msg" target="_blank">current_user.id</a>, 6, 7)</div><div class="m_-5536817573555623173gmail_msg"><br class="m_-5536817573555623173gmail_msg"></div><div class="m_-5536817573555623173gmail_msg">with 6 and 7 being the ID number of the reports I want comparisons from.</div><div class="m_-5536817573555623173gmail_msg"><br class="m_-5536817573555623173gmail_msg"></div><div class="m_-5536817573555623173gmail_msg"><br class="m_-5536817573555623173gmail_msg"></div><div class="m_-5536817573555623173gmail_msg"><br class="m_-5536817573555623173gmail_msg"></div><div class="m_-5536817573555623173gmail_msg"><br class="m_-5536817573555623173gmail_msg"></div><div class="m_-5536817573555623173gmail_msg">I am trying it this way but am getting "wrong number of arguments:</div><div class="m_-5536817573555623173gmail_msg"><br class="m_-5536817573555623173gmail_msg"></div><div class="m_-5536817573555623173gmail_msg"><br class="m_-5536817573555623173gmail_msg"></div><div class="m_-5536817573555623173gmail_msg"><br class="m_-5536817573555623173gmail_msg"></div><div class="m_-5536817573555623173gmail_msg"><br class="m_-5536817573555623173gmail_msg"></div><div class="m_-5536817573555623173gmail_msg"><div class="m_-5536817573555623173gmail_msg">class ReportCard < ActiveRecord::Base</div><div class="m_-5536817573555623173gmail_msg">  belongs_to :user</div><div class="m_-5536817573555623173gmail_msg"><br class="m_-5536817573555623173gmail_msg"></div><div class="m_-5536817573555623173gmail_msg">  attr_accessible :user_id, :oldest_report_stat_id, :newest_report_stat_id, :num_active_and_licensed_aeds,</div><div class="m_-5536817573555623173gmail_msg">  :num_active_sites, :num_users_logged_in, :aeds_total, :aeds_compliant, :aed_sites_total,</div><div class="m_-5536817573555623173gmail_msg">  :aed_sites_compliant, :responders_total, :responders_compliant, :num_active_and_licensed_aeds_<wbr>percentage,</div><div class="m_-5536817573555623173gmail_msg">  :num_active_sites_percentage, :num_users_logged_in_<wbr>percentage, :aeds_compliant_percentage,</div><div class="m_-5536817573555623173gmail_msg">  :aed_site_compliant_<wbr>percentage, :responders_compliant_<wbr>percentage, :report_start_time, :report_end_time</div><div class="m_-5536817573555623173gmail_msg"><br class="m_-5536817573555623173gmail_msg"></div><div class="m_-5536817573555623173gmail_msg"><br class="m_-5536817573555623173gmail_msg"></div><div class="m_-5536817573555623173gmail_msg"><br class="m_-5536817573555623173gmail_msg"></div><div class="m_-5536817573555623173gmail_msg">  def execute</div><div class="m_-5536817573555623173gmail_msg">    @newest_stat = ReportStat.find(self.newest_<wbr>report_stat_id)</div><div class="m_-5536817573555623173gmail_msg">    @oldest_stat = ReportStat.find(self.oldest_<wbr>report_stat_id)</div><div class="m_-5536817573555623173gmail_msg">    #@newest_stat.inspect</div><div class="m_-5536817573555623173gmail_msg">    @newest_stat.assign_<wbr>attributes.each do |attr_name, attr_value|</div><div class="m_-5536817573555623173gmail_msg">      self.send("#{attr_name}=", "#{attr_value}")</div><div class="m_-5536817573555623173gmail_msg">    end</div><div class="m_-5536817573555623173gmail_msg">    # calculate_percentage_change</div><div class="m_-5536817573555623173gmail_msg">  end</div><div class="m_-5536817573555623173gmail_msg"><br class="m_-5536817573555623173gmail_msg"></div><div class="m_-5536817573555623173gmail_msg">end</div><div class="m_-5536817573555623173gmail_msg"><br class="m_-5536817573555623173gmail_msg"></div><div class="m_-5536817573555623173gmail_msg">Here is my rails console output:</div><div class="m_-5536817573555623173gmail_msg"><br class="m_-5536817573555623173gmail_msg"></div><div class="m_-5536817573555623173gmail_msg"><pre style="color:rgb(0,0,0)" class="m_-5536817573555623173gmail_msg">r = ReportCard.new
=> #<ReportCard id: nil, user_id: nil, created_at: nil, updated_at: nil, oldest_report_stat_id: nil, newest_report_stat_id: nil, num_active_and_licensed_aeds: nil, num_active_sites: nil, num_users_logged_in: nil, aeds_total: nil, aeds_compliant: nil, aed_sites_total: nil, aed_sites_compliant: nil, responders_total: nil, responders_compliant: nil, num_active_and_licensed_aeds_<wbr>percentage: nil, num_active_sites_percentage: nil, num_users_logged_in_<wbr>percentage: nil, aeds_compliant_percentage: nil, aed_site_compliant_percentage: nil, responders_compliant_<wbr>percentage: nil, report_start_time: nil, report_end_time: nil>
[2] pry(main)> r.oldest_report_stat_id = 6
=> 6
[3] pry(main)> r.newest_report_stat_id = 7
=> 7
[4] pry(main)> r.execute
  ReportStat Load (1.3ms)  SELECT "report_stats".* FROM "report_stats" WHERE "report_stats"."id" = $1 LIMIT 1  [["id", 7]]
  ReportStat Load (0.4ms)  SELECT "report_stats".* FROM "report_stats" WHERE "report_stats"."id" = $1 LIMIT 1  [["id", 6]]
ArgumentError: wrong number of arguments (0 for 1..2)
from /Users/enpro/.rbenv/versions/<wbr>2.1.1/lib/ruby/gems/2.1.0/<wbr>gems/activerecord-3.2.17/lib/<wbr>active_record/attribute_<wbr>assignment.rb:66:in `assign_attributes'</pre></div><div class="m_-5536817573555623173gmail_msg"><br class="m_-5536817573555623173gmail_msg"></div><div class="m_-5536817573555623173gmail_msg"><br class="m_-5536817573555623173gmail_msg"></div><div class="m_-5536817573555623173gmail_msg">Any ideas? Maybe syntax error? Ive dumped way too much time into this and need to move on to the rest of the feature. Thank you LRUG!</div><div class="m_-5536817573555623173gmail_msg"><br class="m_-5536817573555623173gmail_msg"></div><div class="m_-5536817573555623173gmail_msg"><br class="m_-5536817573555623173gmail_msg"></div><div class="m_-5536817573555623173gmail_msg"><br class="m_-5536817573555623173gmail_msg"></div><div class="m_-5536817573555623173gmail_msg"><br class="m_-5536817573555623173gmail_msg"></div>-- <br class="m_-5536817573555623173gmail_msg"><div class="m_-5536817573555623173m_-5411892012891363774gmail_signature m_-5536817573555623173gmail_msg"><div dir="ltr" class="m_-5536817573555623173gmail_msg"><div class="m_-5536817573555623173gmail_msg"><div dir="ltr" class="m_-5536817573555623173gmail_msg"><div class="m_-5536817573555623173gmail_msg"><div dir="ltr" class="m_-5536817573555623173gmail_msg"><div dir="ltr" class="m_-5536817573555623173gmail_msg"><div class="m_-5536817573555623173gmail_msg">Jesse Waites</div><div class="m_-5536817573555623173gmail_msg">Web Developer</div><div class="m_-5536817573555623173gmail_msg"><a href="http://JesseWaites.com" class="m_-5536817573555623173gmail_msg" target="_blank">JesseWaites.com</a></div></div></div></div></div></div></div></div>
</div></div>
______________________________<wbr>_________________<br class="m_-5536817573555623173gmail_msg">
Chat mailing list<br class="m_-5536817573555623173gmail_msg">
<a href="mailto:Chat@lists.lrug.org" class="m_-5536817573555623173gmail_msg" target="_blank">Chat@lists.lrug.org</a><br class="m_-5536817573555623173gmail_msg">
Archives: <a href="http://lists.lrug.org/pipermail/chat-lrug.org" rel="noreferrer" class="m_-5536817573555623173gmail_msg" target="_blank">http://lists.lrug.org/<wbr>pipermail/chat-lrug.org</a><br class="m_-5536817573555623173gmail_msg">
Manage your subscription: <a href="http://lists.lrug.org/options.cgi/chat-lrug.org" rel="noreferrer" class="m_-5536817573555623173gmail_msg" target="_blank">http://lists.lrug.org/options.<wbr>cgi/chat-lrug.org</a><br class="m_-5536817573555623173gmail_msg">
List info: <a href="http://lists.lrug.org/listinfo.cgi/chat-lrug.org" rel="noreferrer" class="m_-5536817573555623173gmail_msg" target="_blank">http://lists.lrug.org/<wbr>listinfo.cgi/chat-lrug.org</a><br class="m_-5536817573555623173gmail_msg">
</blockquote></div></blockquote></div>
</div></div><br>______________________________<wbr>_________________<br>
Chat mailing list<br>
<a href="mailto:Chat@lists.lrug.org">Chat@lists.lrug.org</a><br>
Archives: <a href="http://lists.lrug.org/pipermail/chat-lrug.org" rel="noreferrer" target="_blank">http://lists.lrug.org/<wbr>pipermail/chat-lrug.org</a><br>
Manage your subscription: <a href="http://lists.lrug.org/options.cgi/chat-lrug.org" rel="noreferrer" target="_blank">http://lists.lrug.org/options.<wbr>cgi/chat-lrug.org</a><br>
List info: <a href="http://lists.lrug.org/listinfo.cgi/chat-lrug.org" rel="noreferrer" target="_blank">http://lists.lrug.org/<wbr>listinfo.cgi/chat-lrug.org</a><br>
<br></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div>Jesse Waites</div><div>Web Developer</div><div><a href="http://JesseWaites.com" target="_blank">JesseWaites.com</a></div></div></div></div></div></div></div></div>
</div>