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
There are just 3 entries in "clients" table with id = 1, 2 and 3.
In "cli_outs" table there are entries with "client_id" = 1, 2 and 3.
This is, there is no cli_out entry with a client_id value not matching
an id entry of "clients" table.
However when I try to open the cli_outs view I get an error:
-----------------------------------------------
Processing CliOutsController#index (for 212.230.46.89 at 2010-05-04
14:41:56) [GET]
Parameters: {"action"=>"index", "controller"=>"cli_outs"}
SQL (0.2ms) SELECT count(*) AS count_all FROM `clis_out`
CliOut Load (0.1ms) SELECT `clis_out`.* FROM `clis_out` ORDER BY
`clis_out`.`cli` ASC LIMIT 0, 40
Rendering template within layouts/application
Rendering list
Rendered _list_header (6.5ms)
Rendered _list_column_headings (13.6ms)
Rendered _messages (1.4ms)
Rendered _list_messages (13.2ms)
Tue May 04 14:41:56 +0200 2010#<NoMethodError: You have a nil object
when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.find> -- on the ActiveScaffold
column = :client_id in CliOutsController
ActionView::TemplateError (You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.find) on line #3 of
vendor/plugins/active_scaffold/frontends/default/views/_list_record_columns.html.erb:
1: <% active_scaffold_config.list.columns.each do |column| %>
2: <% authorized = record.authorized_for?(:crud_type => :read,
:column => column.name) -%>
3: <% column_value = authorized ? get_column_value(record, column) :
active_scaffold_config.list.empty_field_text -%>
4:
5: <td class="<%= column_class(column, column_value) %>" >
6: <%= authorized ? render_list_column(column_value, column,
record) : column_value %>
vendor/plugins/active_scaffold/lib/active_scaffold/helpers/list_column_helpers.rb:121:in
`active_scaffold_column_select'
vendor/plugins/active_scaffold/lib/active_scaffold/helpers/list_column_helpers.rb:16:in
`send'
vendor/plugins/active_scaffold/lib/active_scaffold/helpers/list_column_helpers.rb:16:in
`get_column_value'
vendor/plugins/active_scaffold/frontends/default/views/_list_record_columns.html.erb:3
----------------------------------------------
And when I press "create new" or "update" in cli_outs view I always
get this error:
------------------------------------------------------------------------------------
Processing CliOutsController#new (for 212.230.46.89 at 2010-05-04
14:35:41) [GET]
Parameters: {"action"=>"new", "_method"=>"get",
"adapter"=>"_list_inline_adapter", "controller"=>"cli_outs"}
Rendered _form_attribute (2.8ms)
Tue May 04 14:35:41 +0200 2010#<NoMethodError: You have a nil object
when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.collect> -- on the
ActiveScaffold column = :client_id in CliOutsController
ActionView::TemplateError (You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.collect) on line #7 of
vendor/plugins/active_scaffold/frontends/default/views/_form_attribute.html.erb:
4: <label for="<%= active_scaffold_input_options(column,
scope)[:id] %>"><%= column.label %></label>
5: </dt>
6: <dd>
7: <%= active_scaffold_input_for column, scope %>
8: <% if column.options.is_a?(Hash) &&
column.options[:update_column] -%>
9: <%= loading_indicator_tag(:action => :render_field, :id =>
params[:id]) %>
10: <% end -%>
vendor/plugins/active_scaffold/lib/active_scaffold/helpers/form_column_helpers.rb:144:in
`active_scaffold_input_select'
vendor/plugins/active_scaffold/lib/active_scaffold/helpers/form_column_helpers.rb:16:in
`send'
vendor/plugins/active_scaffold/lib/active_scaffold/helpers/form_column_helpers.rb:16:in
`active_scaffold_input_for'
vendor/plugins/active_scaffold/frontends/default/views/_form_attribute.html.erb:7
------------------------------------------------------------------------------------
I've checked and re-checked it and cannot find the issue. Any tip please?
> 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 :(
Really thanks a lot for all your useful help.
--
Iñaki Baz Castillo
<[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.