Forum: Rails Engines meta-programming to get user data?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
7be98b1602d3a3842e8f8602118bc9cd?d=identicon&s=25 steve ross (Guest)
on 2006-06-09 22:22
(Received via mailing list)
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
05d703f649ef1d07e78d7b479fb4c4ac?d=identicon&s=25 James Adam (Guest)
on 2006-06-09 22:31
(Received via mailing list)
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
7be98b1602d3a3842e8f8602118bc9cd?d=identicon&s=25 steve ross (Guest)
on 2006-06-09 22:44
(Received via mailing list)
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
A63764f318f10379c8b51349b757cf4b?d=identicon&s=25 Jay Levitt (Guest)
on 2006-06-11 16:32
(Received via mailing list)
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
This topic is locked and can not be replied to.