# Meta-programming to get user data?

**URL:** <https://www.ruby-forum.com/t/meta-programming-to-get-user-data/62960>\
**Category:** Engines\
**Created:** [June 9, 2006, 10:22pm UTC](https://www.ruby-forum.com/t/meta-programming-to-get-user-data/62960 "2006-06-09T22:22:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![steve\_ross](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/3d9bf3/32.png) [@steve\_ross](https://www.ruby-forum.com/u/steve_ross)\
**Post date:** [June 9, 2006, 10:22pm UTC](https://www.ruby-forum.com/t/meta-programming-to-get-user-data/62960/1 "2006-06-09T22:22:00Z")

</div>

I’m using login\_engine and would like to create an acts\_as\_identified  
plugin instead of establishing a has\_one/belongs\_to relationship (I’m  
using two different databases). Here’s how it would work:

class MyModel \< ActiveRecord::Base  
acts\_as\_identified  
end

By the simple addition of this macro, the following things happen:

MyModel acquire new accessors, based on the login information for a  
given user. These read accessors are:

user\_id  
full\_name  
email

I have a foggy notion of how to create an acts\_as\_chunky\_bacon or  
acts\_as\_chicken macro, but what I want is something that triggers  
immediately as the class is being built in much the same way  
acts\_as\_tree does, to add this magic. Additionally, I need to reach out  
and touch the session store from the model (ackkk!)

Any pointers are immensely appreciated! I promise full code, plus some  
extras if I can get this to work 🙂

Thanks

---

<div class="post-metadata">

**Author:** ![steve\_ross](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/3d9bf3/32.png) [@steve\_ross](https://www.ruby-forum.com/u/steve_ross)\
**Post date:** [June 9, 2006, 10:31pm UTC](https://www.ruby-forum.com/t/meta-programming-to-get-user-data/62960/2 "2006-06-09T22:31:43Z")

</div>

I’m not 100% clear as to what you want this acts\_as\_\* to do. Can you  
give a more concrete example?

- james

On 9 Jun 2006 20:19:52 -0000, steve ross

---

<div class="post-metadata">

**Author:** ![steve\_ross](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/3d9bf3/32.png) [@steve\_ross](https://www.ruby-forum.com/u/steve_ross)\
**Post date:** [June 9, 2006, 10:44pm UTC](https://www.ruby-forum.com/t/meta-programming-to-get-user-data/62960/3 "2006-06-09T22:44:38Z")

</div>

The problem is that I have a faux database table simply for the purpose  
of generating forms (Rails Recipes has a way of doing this from non-AR  
objects, but I’m currently using SQLite memory dbs). The problem is that  
to access the form, a user must be logged in, and once they complete the  
form, I acknowledge that by sending them an email to the address  
contained in the users table.

I have the choice of manually stuffing information from the session  
object into the AR object in each controller (there are tons of forms  
like this), or I can repeat myself a bit less by some clever  
metaprogramming. Maybe acts\_as\_\* is not the right way to do this, but  
there just has to be a way to add a couple of accessible attributes to a  
model without typing in the code each time, right?

Thanks

---

<div class="post-metadata">

**Author:** ![steve\_ross](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/3d9bf3/32.png) [@steve\_ross](https://www.ruby-forum.com/u/steve_ross)\
**Post date:** [June 11, 2006, 4:32pm UTC](https://www.ruby-forum.com/t/meta-programming-to-get-user-data/62960/4 "2006-06-11T16:32:18Z")

</div>

On 9 Jun 2006 20:41:35 -0000, steve ross wrote:

> Maybe acts\_as\_\* is not the right way to do this, but  
> there just has to be a way to add a couple of accessible attributes to a  
> model without typing in the code each time, right?

Have you checked out model\_security? If I understand right, you want to  
limit access to actual model elements, instead of just view elements.  
That’s what model\_security does - and I think if you could integrate it  
better with login\_engine, lots of people would be very happy.

Jay
