<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
	<channel>
		<title><![CDATA[Rails Forum - Ruby on Rails Help and Discussion Forum - filtering load_resource results in CanCan]]></title>
		<link>http://railsforum.com/viewtopic.php?id=48545</link>
		<description><![CDATA[The most recent posts in filtering load_resource results in CanCan.]]></description>
		<lastBuildDate>Fri, 13 Apr 2012 13:41:36 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[filtering load_resource results in CanCan]]></title>
			<link>http://railsforum.com/viewtopic.php?pid=151759#p151759</link>
			<description><![CDATA[<p>The CanCan documents state that the :index method, of necessity, ignores any hash of conditions when checking a class and returns true, as in:</p><p>&nbsp; can :read, MedicalRecord, :patient_id =&gt; user.id<br />&nbsp; can? :read, MedicalRecord # returns true</p><p>So if I want MedicalRecordsController#index to ONLY return medical records for the current user, what&#039;s the right technique?&nbsp; What I&#039;ve done -- and it appears to work -- is to exploit the fact that load_resource sets @medical_records to a relation, and do further filtering on that:</p><p>&nbsp; &nbsp; class MedicalRecordsController<br />&nbsp; &nbsp; &nbsp; load_and_authorize_resource<br />&nbsp; &nbsp; &nbsp; def index<br />&nbsp; &nbsp; &nbsp; &nbsp; @medical_records = @medical_records.where(:patient_id =&gt; current_user.id)<br />&nbsp; &nbsp; &nbsp; end<br />&nbsp; &nbsp; &nbsp; ...<br />&nbsp; &nbsp; end</p><p>Is this the approved technique?</p><p>- ff</p>]]></description>
			<author><![CDATA[dummy@example.com (fearless_fool)]]></author>
			<pubDate>Fri, 13 Apr 2012 13:41:36 +0000</pubDate>
			<guid>http://railsforum.com/viewtopic.php?pid=151759#p151759</guid>
		</item>
	</channel>
</rss>
