On Martes, 4 de Mayo de 2010 13:06:46 Iñaki Baz Castillo escribió:
> ok ok! it occurs because I'm using form_ui = :select for client_id column:
>
> config.columns[:client_id].form_ui = :select
> config.columns[:client_id].options = {:options => Client.array}
>
> and array looks as follows:
>
> [["-", nil], ["alice", 1], ["bob", 2], ["carol", 3]
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. 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.
>
> Such array is generated dynamically retrieving "id" and "name" columns
> from the 'client' table. I use it to display the names of the clients
> in the select.
> When I select "-" then the value to store should be nil, but I think
> it's converted to 0.
Select form_ui when is used for non-association columns support i18n,
translating the first value if it's possible, and when second value is missing
uses the first value for the value attribute of the option tag. When second
value is missing, ruby returns nil, so nil value is being confused with
missing value.
If you check the generated html code you will see:
<option value='-'>-</option>
And then ruby will convert '-' to 0 when is set to client_id.
>
> In fact, I've changed such array to this:
>
> [["-", ""], ["alice", 1], ["bob", 2], ["carol", 3]
>
> this is, using "" instead of nil and then NULL is stored :)
>
> So problem solved, but I wonder why it stores 0 if I give it nil value.
>
> Thanks a lot.
>
> --
> 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.