<div dir="ltr">Correction: "<span style="color:rgb(33,33,33)">I think you are looking for *something that can iterate*"</span></div><br><div class="gmail_quote"><div dir="ltr">On Wed, 8 Mar 2017 at 14:10 Toby Privett <<a href="mailto:tobyprivett@gmail.com">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">http://apidock.com/rails/v4.2.7/ActiveRecord/AttributeAssignment/assign_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">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="gmail_msg">Hi all--<div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_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="gmail_msg"><br class="gmail_msg"></div><div class="gmail_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="gmail_msg"><br class="gmail_msg"></div><div class="gmail_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="gmail_msg"><br class="gmail_msg"></div><div class="gmail_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="gmail_msg"><br class="gmail_msg"></div><div class="gmail_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="gmail_msg" target="_blank">current_user.id</a>, 6, 7)</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">with 6 and 7 being the ID number of the reports I want comparisons from.</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">I am trying it this way but am getting "wrong number of arguments:</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg"><div class="gmail_msg">class ReportCard < ActiveRecord::Base</div><div class="gmail_msg"> belongs_to :user</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg"> attr_accessible :user_id, :oldest_report_stat_id, :newest_report_stat_id, :num_active_and_licensed_aeds,</div><div class="gmail_msg"> :num_active_sites, :num_users_logged_in, :aeds_total, :aeds_compliant, :aed_sites_total,</div><div class="gmail_msg"> :aed_sites_compliant, :responders_total, :responders_compliant, :num_active_and_licensed_aeds_percentage,</div><div class="gmail_msg"> :num_active_sites_percentage, :num_users_logged_in_percentage, :aeds_compliant_percentage,</div><div class="gmail_msg"> :aed_site_compliant_percentage, :responders_compliant_percentage, :report_start_time, :report_end_time</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg"> def execute</div><div class="gmail_msg"> @newest_stat = ReportStat.find(self.newest_report_stat_id)</div><div class="gmail_msg"> @oldest_stat = ReportStat.find(self.oldest_report_stat_id)</div><div class="gmail_msg"> #@newest_stat.inspect</div><div class="gmail_msg"> @newest_stat.assign_attributes.each do |attr_name, attr_value|</div><div class="gmail_msg"> self.send("#{attr_name}=", "#{attr_value}")</div><div class="gmail_msg"> end</div><div class="gmail_msg"> # calculate_percentage_change</div><div class="gmail_msg"> end</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">end</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">Here is my rails console output:</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg"><pre style="color:rgb(0,0,0)" class="gmail_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_percentage: nil, num_active_sites_percentage: nil, num_users_logged_in_percentage: nil, aeds_compliant_percentage: nil, aed_site_compliant_percentage: nil, responders_compliant_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/2.1.1/lib/ruby/gems/2.1.0/gems/activerecord-3.2.17/lib/active_record/attribute_assignment.rb:66:in `assign_attributes'</pre></div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_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="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg"><br class="gmail_msg"></div>-- <br class="gmail_msg"><div class="m_-5411892012891363774gmail_signature gmail_msg"><div dir="ltr" class="gmail_msg"><div class="gmail_msg"><div dir="ltr" class="gmail_msg"><div class="gmail_msg"><div dir="ltr" class="gmail_msg"><div dir="ltr" class="gmail_msg"><div class="gmail_msg">Jesse Waites</div><div class="gmail_msg">Web Developer</div><div class="gmail_msg"><a href="http://JesseWaites.com" class="gmail_msg" target="_blank">JesseWaites.com</a></div></div></div></div></div></div></div></div>
</div></div>
_______________________________________________<br class="gmail_msg">
Chat mailing list<br class="gmail_msg">
<a href="mailto:Chat@lists.lrug.org" class="gmail_msg" target="_blank">Chat@lists.lrug.org</a><br class="gmail_msg">
Archives: <a href="http://lists.lrug.org/pipermail/chat-lrug.org" rel="noreferrer" class="gmail_msg" target="_blank">http://lists.lrug.org/pipermail/chat-lrug.org</a><br class="gmail_msg">
Manage your subscription: <a href="http://lists.lrug.org/options.cgi/chat-lrug.org" rel="noreferrer" class="gmail_msg" target="_blank">http://lists.lrug.org/options.cgi/chat-lrug.org</a><br class="gmail_msg">
List info: <a href="http://lists.lrug.org/listinfo.cgi/chat-lrug.org" rel="noreferrer" class="gmail_msg" target="_blank">http://lists.lrug.org/listinfo.cgi/chat-lrug.org</a><br class="gmail_msg">
</blockquote></div></blockquote></div>