<html><head><style>body{font-family:Helvetica,Arial;font-size:13px}</style></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px; color: rgba(0,0,0,1.0); margin: 0px; line-height: auto;">On 21 April 2015 at 16:30:00, Tom Armitage (<a href="mailto:tom@infovore.org">tom@infovore.org</a>) wrote:</div> <blockquote type="cite" class="clean_bq"><span><div><div></div><div>
<title></title>
<div dir="ltr">User is indeed a subclass of ActiveRecord::Base, and
current_user is a User, and yet include appears to fail magically.
<div><br></div>
<div>I'm going to stick to testing on IDs, then, which works, and
perhaps try to understand this another day.</div>
<div><br></div></div></div></div></span></blockquote><div><br></div><div><br></div><div>Could this be an annoying development mode code reloading issue?</div><div><br></div><div>If current_user is an instance of the current User class but another_user is an instance of a since unloaded version of the user class then current_user == another_user will be false (at least according to a quick experiment) even if they did correspond to the same row in the database</div><div><br></div><div>The readme for clearance does look like they might lead you down that route since it stashes User as part of an initializer which it presumably continues to use post reloading of your code.</div><div><br></div><div>A simple test for this would be to compare current_user.class.object_id to the object_ids of the class of the things inside this array you are using.</div><div><br></div>Fred<div><br><blockquote type="cite" class="clean_bq"><span><div><div><div dir="ltr">
<div>t.</div>
</div>
<div class="gmail_extra"><br>
<div class="gmail_quote">On Tue, Apr 21, 2015 at 4:10 PM, Tom
Stuart <span dir="ltr"><<a href="mailto:tom@codon.com" target="_blank">tom@codon.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<span class="">On 21 Apr 2015, at 15:56, Stephen Best <<a href="mailto:bestie@gmail.com">bestie@gmail.com</a>> wrote:<br>
> To make Array#include? work as you expect for two different
instances of the same user record you would have to redefine
equality (User#==) in terms of the object values or maybe just the
id.<br>
<br></span>If `User` is a subclass of `ActiveRecord::Base`, the
`User#==` method should already do this: <a href="https://github.com/rails/rails/blob/4-2-stable/activerecord/lib/active_record/core.rb#L377-L391" target="_blank">https://github.com/rails/rails/blob/4-2-stable/activerecord/lib/active_record/core.rb#L377-L391</a><br>
<br>
Cheers,<br>
-Tom<br>
<div class="HOEnZb">
<div class="h5">
_______________________________________________<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" target="_blank">http://lists.lrug.org/pipermail/chat-lrug.org</a><br>
Manage your subscription: <a href="http://lists.lrug.org/options.cgi/chat-lrug.org" target="_blank">http://lists.lrug.org/options.cgi/chat-lrug.org</a><br>
List info: <a href="http://lists.lrug.org/listinfo.cgi/chat-lrug.org" target="_blank">http://lists.lrug.org/listinfo.cgi/chat-lrug.org</a><br></div>
</div>
</blockquote>
</div>
<br>
<br clear="all">
<div><br></div>
--<br>
<div class="gmail_signature">Tom Armitage<br>
<a href="http://infovore.org" target="_blank">http://infovore.org</a><br>
07813 060578</div>
</div>
_______________________________________________
<br>Chat mailing list
<br>Chat@lists.lrug.org
<br>Archives: http://lists.lrug.org/pipermail/chat-lrug.org
<br>Manage your subscription: http://lists.lrug.org/options.cgi/chat-lrug.org
<br>List info: http://lists.lrug.org/listinfo.cgi/chat-lrug.org
<br></div></div></span></blockquote></div></body></html>