On Martes, 4 de Mayo de 2010 14:46:09 Iñaki Baz Castillo escribió:
> 2010/5/4 Sergio Cambra .:: entreCables S.L. ::. <[email protected]>:
> > Why don't you use client association?
> > #model
> > belongs_to :client
> >
> > #controller
> > config.columns[:client].form_ui = :select
> >
> > Then ActiveScaffold will fill the select with all clients automatically.
>
> Hi, I already tryed it but get always an error (see below the trace)
> when trying list, create or update an entry,
> Associations are already done:
>
> Client model:
>     has_many :cli_outs, :primary_key => :id, :foreign_key =>
>
> :client_id, :dependent => :destroy
>
> CliOut model:
>     belongs_to :client, :primary_key => :id, :foreign_key => :client_id
>
> In CliOutsController I have:
>    config.columns = [:cli, :client_id]
>    config.columns[:client_id].form_ui = :select


I think you don't need to set primary_key neither foreign_key options. And you 
have to use client column:
config.columns = [:cli, :client]
config.columns[:client].form_ui = :select

> > Also,
> > code from above won't work in production mode, it will load the clients
> > in startup time and new clients won't appear in select box until
> > application is restarted.
>
> Well, it will work as I compute the hash (Client.all.map....) each
> time, which of course is very inneficient so I'd really like to
> improve it by making your suggestion to work, but I can't do it as
> shown above, no idea what is wrong :(

Are you sure? When app is started, class is loaded, while class is being 
loaded Client.array is called and saved in ActiveScaffold config, which is 
stored in a class variable. In each request, column is rendered using options 
saved in a class variable, and new clients are not in that variable. It works 
in development mode because classes are reloaded for each request.

>
>
> Really thanks a lot for all your useful help.
>
> --
> Iñaki Baz Castillo
> <[email protected]>

-- 
Sergio Cambra .:: entreCables S.L. ::.
Mariana Pineda 23, 50.018 Zaragoza
T) 902 021 404 F) 976 52 98 07 E) [email protected]

-- 
You received this message because you are subscribed to the Google Groups 
"ActiveScaffold : Ruby on Rails plugin" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/activescaffold?hl=en.

Reply via email to