# Virtual attribute setter method in model, how to write a scoped query?

**URL:** <https://www.ruby-forum.com/t/virtual-attribute-setter-method-in-model-how-to-write-a-scoped-query/150677>\
**Category:** Rails\
**Created:** [October 11, 2008, 11:16am UTC](https://www.ruby-forum.com/t/virtual-attribute-setter-method-in-model-how-to-write-a-scoped-query/150677 "2008-10-11T11:16:10Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![vinay](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/6a8cbe/32.png) [@vinay](https://www.ruby-forum.com/u/vinay)\
**Post date:** [October 11, 2008, 11:16am UTC](https://www.ruby-forum.com/t/virtual-attribute-setter-method-in-model-how-to-write-a-scoped-query/150677/1 "2008-10-11T11:16:10Z")

</div>

I have a form that has a virtual attribute ‘contact\_name’. In the  
setter method for this, I need to scope the query through  
current\_user.contacts.find (etc). But current\_user is a helper method  
(RESTful authentication) and it is apparently not available in the  
model (where the setter method is located). I tried…

`@current_user = User.find(params[:user_id])
@contact = @current_user.contacts.find (etc)`  
… but the params hash too is not available. How can I scope the query  
through the current\_user in the model file?

---

<div class="post-metadata">

**Author:** ![vinay](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/6a8cbe/32.png) [@vinay](https://www.ruby-forum.com/u/vinay)\
**Post date:** [October 13, 2008, 12:58pm UTC](https://www.ruby-forum.com/t/virtual-attribute-setter-method-in-model-how-to-write-a-scoped-query/150677/2 "2008-10-13T12:58:31Z")

</div>

anyone got any ideas? i really need a solution for this to get a  
feature working.
