PiRSquared17 / activescaffold

Automatically exported from code.google.com/p/activescaffold
MIT License
0 stars 0 forks source link

active_scaffold_config.columns doesn't seem to work #691

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1.Tryed to add a helper as in  
http://groups.google.com/group/recordselect/browse_thread/thread/ac464340b8d7081
c?pli=1

My helper is 
  def order_type_field_form_column(record,input_name)
     column = active_scaffold_config.columns[:order_type_field] 
     options = active_scaffold_input_options(column)
     active_scaffold_input_record_select(column, options)
  end

What is the expected output? What do you see instead?

It supposed to work but it seems that active_scaffold_config.columns[: 
order_type_field]  cannot 
be accessed although active_scaffold_config.columns exists. Column exists, when 
I've tried to 
use update_column to updated the column for which the helper is, I can access 
active_scaffold_config.columns[: order_type_field]  on ajax update call 

What version (or revision) of the product are you using?
master rails 2.3.2

If this bug causes an exception, please paste at least the first 20 lines below.

Rendered _horizontal_subform_header (155.8ms)

ActionView::TemplateError (You have a nil object when you didn't expect it!
The error occurred while evaluating nil.name) 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.description -%>
9:       <span class="description"><%= column.description %></span>
10:     <% end -%>

    app/helpers/admin/order_items_helper.rb:6:in `order_type_field_form_column'
    vendor/plugins/active_scaffold/frontends/default/views/_form_attribute.html.erb:7

vendor/plugins/active_scaffold/frontends/default/views/_horizontal_subform_recor
d.html.erb:1
5

vendor/plugins/active_scaffold/frontends/default/views/_horizontal_subform_recor
d.html.erb:6
    vendor/plugins/active_scaffold/frontends/default/views/_horizontal_subform.html.erb:15
    vendor/plugins/active_scaffold/frontends/default/views/_horizontal_subform.html.erb:6:in 
`each_index'
    vendor/plugins/active_scaffold/frontends/default/views/_horizontal_subform.html.erb:6
    vendor/plugins/active_scaffold/frontends/default/views/_form_association.html.erb:18
    vendor/plugins/active_scaffold/frontends/default/views/_form.html.erb:10
    vendor/plugins/active_scaffold/frontends/default/views/_form.html.erb:2
    vendor/plugins/active_scaffold/frontends/default/views/_update_form.html.erb:42
    -e:1:in `load'
    -e:1

Original issue reported on code.google.com by andre...@gmail.com on 19 Jun 2009 at 4:32

GoogleCodeExporter commented 9 years ago

 I figured out why it's happening, it happens for subforms on a new record because the record doesn't really 
exists so instead of accessing association's model columns you access master 
model columns.

Original comment by andre...@gmail.com on 21 Jun 2009 at 2:18

GoogleCodeExporter commented 9 years ago
What is line 6 in app/helpers/admin/order_items_helper.rb?

Original comment by sergio.c...@gmail.com on 22 Jun 2009 at 9:57

GoogleCodeExporter commented 9 years ago
options = active_scaffold_input_options(column)

 active_scaffold_config.columns[:order_type_field] is nil if the record is new

 I have Order which has many OrderItems, when I edit Order I can add OrderItems, and activescaffold 
automatically add a new OrderItem by default. For the new record of OrderItems 
active_scaffold_config.columns 
points to Order columns not OrderItems columns as it should

Original comment by andre...@gmail.com on 22 Jun 2009 at 12:25

GoogleCodeExporter commented 9 years ago
active_scaffold_config is the configuration of active_scaffold in the current
controller (current controller is the controller called by current request). If 
you
want to accesss active_scaffold_config for other controller use
active_scaffold_config_for(model).

Really I think the problem is active_scaffold should call override helpers with
options instead of only field's name.

Original comment by sergio.c...@gmail.com on 22 Jun 2009 at 9:22

GoogleCodeExporter commented 9 years ago

 I see, it's a little bit confusing because the helper is for order_items_controller and that point when the record 
for association is new active_scaffold_config actually contains the config for 
order_controller which is for the 
order model. You are right some extra parameters will be helpful, even id for 
the input field because that is used 
for the update_column feature. I think this all thing with associations is a 
little bit hard to handle.

Original comment by andre...@gmail.com on 22 Jun 2009 at 9:44

GoogleCodeExporter commented 9 years ago
active_scaffold_config must contain config for OrdersController for old order 
items
too, because the request is the same, so current controller must be 
OrdersController
too.

If you have the helper in OrderItemsHelper, then it's being used because you 
have
helper :all in your ApplicationController

I think it's needed to pass all parameters to helpers because id is sometimes
needed, I have used active_scaffold_config and active_scaffold_input_options 
many
times only to get the id.

I don't know how to add the options to overrides calls: changing input_name with
options and breaking compatibility, or checking helper's arity is 3 and adding
options as third parameter.

Original comment by sergio.c...@gmail.com on 23 Jun 2009 at 10:45

GoogleCodeExporter commented 9 years ago

Original comment by sergio.c...@gmail.com on 16 Sep 2009 at 10:33