umm. personally i would shun this idea. rails by default loads all
code on startup (in production mode) unless you specifically told the
vm to load your new models they would not get loaded. and when
removed not removed.
Another Idea:
create the objects dynamically. i havent looked into it but im sure
its quite possible to create the class during runtime, and class_eval
{ set_table_name :blah ; set_primary_key };
i would also keep a list of table names and incase you ever have to
bounce/reload your environment you can recreate the class''s again.
Depending on what exactly your doing i thnk id personally just make a
generic Model class and create an initializer that accepts tablename
and primary key name.
On 8/26/05, Jeremy Stephens
<jeremy.f.stephens-GISIphQPqQyKDjD76uxLDg@public.gmane.org>
wrote:> This might be a stupid idea.... but is it possible to call the generator
> script from within a controller? I''m trying to set it up so that
users
> can generate new models/controllers through the web interface, and I
> tried doing something like this in my controller code:
>
> require File.dirname(__FILE__) +
''/../../config/environment''
> require ''rails_generator''
> require ''rails_generator/scripts/generate''
>
> class ResponseTypesController < ApplicationController
> layout "default"
>
> def create
> @response_type = ResponseType.new(params[:response_type])
> if @response_type.save
>
Rails::Generator::Scripts::Generate.new.run([''response_type'',
@response_type.name])
> @response_type.create_response_type(@response_type.name) # a
custom method I made
> flash[:notice] = ''ResponseType was successfully
created.''
> redirect_to :action => ''index'',
:controller => ''main''
> else
> render :action => ''new''
> end
> end
>
> def new
> @response_type = ResponseType.new
> end
> end
>
>
> Here''s the error I get when I try to do this:
> ArgumentError in <controller not set>#<action not set>
> couldn''t find HOME environment -- expanding `~''
>
> It dies in the generator lookup:
>
>
|/usr/lib/ruby/gems/1.8/gems/rails-0.13.1/lib/rails_generator/lookup.rb:33:in
`expand_path''
>
/usr/lib/ruby/gems/1.8/gems/rails-0.13.1/lib/rails_generator/lookup.rb:33:in
`user_home''
>
/usr/lib/ruby/gems/1.8/gems/rails-0.13.1/lib/rails_generator/lookup.rb:102:in
`use_component_sources!''
>
/usr/lib/ruby/gems/1.8/gems/rails-0.13.1/lib/rails_generator/lookup.rb:54:in
`append_features''
> |
>
> Is there an easy fix for this, or should I just not even try to run the
> generator script from within a controller to begin with?
>
>
> Thanks,
> Jeremy
>
> --
> Jeremy Stephens Computer Systems Analyst I School of Medicine
> Department of Biostatistics Vanderbilt University
>
> _______________________________________________
> Rails mailing list
> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
--
Zachery Hostens <zacheryph-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>