Forum: Rails Engines development Re: Engine installer

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Vincent AE Scott (Guest)
on 2006-04-06 14:58
(Received via mailing list)
Hi there,
I'm running into a spot of bother with an engine I'm developing.  I want
the table names I'm using to be configurable by the end user, such that
nothing is hard coded.  Having looked through user_engine, I see it
makes use of things like: UserEngine.config(:some_table).  I'm trying
todo the same thing, like in the following:

 has_many :mac_user_grants, :class_name =>

But when i come to use the class this is in I get an error like the

NameError: undefined local variable or method `mac_user_grants' for

in my mac_engine.rb file, I have the following:

module MacEngine
	if ActiveRecord::Base.pluralize_table_names
		config :mac_user_grant_table, "mac_user_grants"
		config :mac_user_grant_table, "mac_user_grant"

I'm guessing the problem lies with how/what
MacEngine.config(:mac_user_grant_table) returns, and how it gets

I've tried the following to no avail:

:class_name => "#{MacEngine.config(:mac_user_grant_table)}"
:class_name => MacEngine.config(:mac_user_grant_table).to_s

So my question is, and its probably more of a general Ruby question than
an engines one, what is :class_name expecting, and how can i provide it?



 Mankind must put an end to war, or war will put an end to mankind
 -- JFK
Vincent AE Scott (Guest)
on 2006-04-06 15:01
(Received via mailing list)
oops, appologies for replying to a previous post and forgetting to
change the subject line after having removed the InReplyTo:


 Heisenberg may have slept here
Jeff L. (Guest)
on 2006-04-06 15:07
(Received via mailing list)
Well, I'll respond here then.

If you look at some of the examples that use the :class_name
parameter, it does want strings, but of the actual *class* name, not
the table name. Luckily Rails rocks and provides a method on string to
convert a table name to a class name:

:class_name => MacEngine.config(:mac_user_grant_table).classify

I think that should do it.


On 4/6/06, Vincent AE Scott <removed_email_address@domain.invalid> wrote:
> engine-developers mailing list
> removed_email_address@domain.invalid

Jeff L.
Vincent AE Scott (Guest)
on 2006-04-06 15:13
(Received via mailing list)
#if progrium /* Apr 06, 04:04 */
> I think that should do it.

Ahha! perfect, appologies for not RTFM'in

Just before you responded i tried:
"MacEngine::" + MacEngine.config(:mac_user_grant_table).to_s.camelize

and that also failed to work, I guess for exactly the same reason.

> -jeff
#endif /* removed_email_address@domain.invalid */


 When the rich wage war, it's the poor who die.
 -- Jean-Paul Sartre
James A. (Guest)
on 2006-04-06 15:22
(Received via mailing list)
It's a Rails question, rather than a Ruby one, but here goes.

The :class_name argument is expecting something of the form
"MacUserGrants", and that might not be the same as your table name
(which is probably "mac_user_grants", as you set it in the config).
It's expecting a string representation of an actual Ruby class (and a
subclass of ActiveRecord::Base in this particular case).

I think you're more likely to want to do something like this:

class Something < ActiveRecord::Base
   has_many :mac_user_grants

class MacUserGrants < ActiveRecord::Base
  set_table_name MacEngine.config(:mac_user_grants_table)

... the table name is only really relevant in the class which stores
data in that table in this case.

- james

On 4/6/06, Vincent AE Scott <removed_email_address@domain.invalid> wrote:
> following:
>         end
>  -- JFK
> _______________________________________________
> engine-developers mailing list
> removed_email_address@domain.invalid

* J *
This topic is locked and can not be replied to.