PiRSquared17 / activescaffold

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

STI model with association gets "can't dup NilClass" error. #762

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Sample code:

Models:
class Parent < ActiveRecord::Base
end
class Child < Parent
  belongs_to :product
end
class Product < ActiveRecord::Base
  has_many :children
end

Controller:
require "parent" #Does not load Child without that
class ChildController < ApplicationController
  active_scaffold :child
end

I should expect to not see the "can't dup NilClass" error.

I am using latest AS from github `master` branch. (Downloaded on 2010-08-21)

Here's what I get:
-----------------------------------------------
TypeError in Child#new

Showing 
vendor/plugins/active_scaffold/frontends/default/views/_form_attribute.html.erb 
where line #7 raised:

can't dup NilClass
Extracted source (around line #7):

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 -%>

Framework trace first few lines:
/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:2219:in
 `dup'
/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:2219:in
 `scoped_methods'
/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:2223:in
 `current_scoped_methods'
/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:2213:in
 `scope'
/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:2448:in
 `set_readonly_option!'
/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:613:in 
`find'
/home/sarunas/Projects/small_tests/sti/vendor/plugins/active_scaffold/lib/active
_scaffold/helpers/association_helpers.rb:6:in `association_options_find'
/home/sarunas/Projects/small_tests/sti/vendor/plugins/active_scaffold/lib/active
_scaffold/helpers/association_helpers.rb:15:in `options_for_association'
/home/sarunas/Projects/small_tests/sti/vendor/plugins/active_scaffold/lib/active
_scaffold/helpers/form_column_helpers.rb:107:in 
`active_scaffold_input_singular_association'
/home/sarunas/Projects/small_tests/sti/vendor/plugins/active_scaffold/lib/active
_scaffold/helpers/form_column_helpers.rb:158:in `active_scaffold_input_select'
/home/sarunas/Projects/small_tests/sti/vendor/plugins/active_scaffold/lib/active
_scaffold/helpers/form_column_helpers.rb:16:in `send'
/home/sarunas/Projects/small_tests/sti/vendor/plugins/active_scaffold/lib/active
_scaffold/helpers/form_column_helpers.rb:16:in `active_scaffold_input_for'
/home/sarunas/Projects/small_tests/sti/vendor/plugins/active_scaffold/frontends/
default/views/_form_attribute.html.erb:7:in 
`_run_erb_vendor47plugins47active_scaffold47frontends47default47views47_form_att
ribute46html46erb_locals_column_form_attribute_object'
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.8/lib/action_view/renderable.rb:34:in
 `send'

Original issue reported on code.google.com by shara...@gmail.com on 20 Aug 2010 at 10:10

GoogleCodeExporter commented 9 years ago
If ActiveScaffold can't guess your reverse association, you must set in your 
controller:

config.columns[:product].association.reverse = :children

Original comment by sergio.c...@gmail.com on 23 Aug 2010 at 7:12