# What's wrong with this code? (hitting my head against a wall)

**URL:** <https://www.ruby-forum.com/t/whats-wrong-with-this-code-hitting-my-head-against-a-wall/153874>\
**Category:** Rails\
**Created:** [November 22, 2008, 6:36am UTC](https://www.ruby-forum.com/t/whats-wrong-with-this-code-hitting-my-head-against-a-wall/153874 "2008-11-22T06:36:21Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![greg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/71c47a/32.png) [@greg](https://www.ruby-forum.com/u/greg)\
**Post date:** [November 22, 2008, 6:36am UTC](https://www.ruby-forum.com/t/whats-wrong-with-this-code-hitting-my-head-against-a-wall/153874/1 "2008-11-22T06:36:21Z")

</div>

Hi,

I’m just trying to load a set of options which doesn’t require tables  
(i.e. using tableless plugin).

Error when going to view at “[http://localhost:3000/graph2/edit](http://localhost:3000/graph2/edit)” is  
undefined method `calc\_type’ for Line(Table doesn’t exist):Class

Thanks in advance - details below:

-----controller------  
class Graph2Controller \< ApplicationController

def edit  
# Default parameters for form  
@graph\_options = GraphOptions.new  
@graph\_options.start\_date = Time.now.to\_date - 3.months  
@graph\_options.end\_date = Time.now.to\_date + 3.months  
@graph\_options.granularity = 1  
@graph\_options.lines.build  
@graph\_options.lines[0].calc\_type = “manual calc”

end

def save  
@graph\_options = GraphOptions.new(params[:graph\_options])  
render :action =\> “edit” if !@graph\_options.valid?  
end

end

-------- model ------  
class GraphOptions \< ActiveRecord::BaseWithoutTable  
column :label\_title, :string  
column :start\_date, :date  
column :end\_date, :date  
column :granularity, :integer

has\_many :lines

validates\_presence\_of :label\_title  
validates\_numericality\_of :granularity  
validates\_associated :lines

def validate  
errors.add(‘start\_date’, ‘is not in Date format’) if  
!start\_date.kind\_of?(Date)  
errors.add(‘end\_date’, ‘is not in Date format’) if  
!end\_date.kind\_of?(Date)  
end

end

class Line \< ActiveRecord::BaseWithoutTable  
column :calc\_type, :string  
validates\_presence\_of :calc\_type  
end

----- view -------

# Graph Options Selection

\<% form\_for :graph\_options, :url =\> {:action =\> ‘save’} do |f| %\>  
\<%= f.error\_messages %\>

| Graph Title: | \<%= f.text\_field :label\_title %\> |
| Start Date: | \<%= f.calendar\_date\_select :start\_date %\> |
| End Date: | \<%= f.calendar\_date\_select :end\_date %\> |
| Granularity (days): | \<%= f.text\_field :granularity %\> |

\<% fields\_for “graph\_options[lines][]”, @graph\_options.lines do  
|fields| %\>  
Calculation Type: \<%= fields.text\_field ‘calc\_type’ %\>

# \<=== ERROR IS HERE

\<% end %\>

\<%= submit\_tag ‘Create Graph’ %\>

\<% end %\>

-------Error----------  
NoMethodError in Graph2#edit

Showing graph2/edit.html.erb where line #13 raised:

undefined method `calc\_type’ for Line(Table doesn’t exist):Class

Extracted source (around line #13):

10:   
11:  
12: \<% fields\_for “graph\_options[lines][]”, @graph\_options.lines do  
|fields| %\>  
13: Calculation Type: \<%= fields.text\_field ‘calc\_type’ %\>  
14: \<% end %\>  
15:  
16:

RAILS\_ROOT: /Users/greg/source/myequity  
Application Trace | Framework Trace | Full Trace

/opt/local/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/active\_record/base.rb:1672:in  
`method_missing' /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/active_record/associations/association_collection.rb:288:in `send’  
/opt/local/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/active\_record/associations/association\_collection.rb:288:in  
`method_missing' /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/active_record/base.rb:1857:in `with\_scope’  
/opt/local/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/active\_record/associations/association\_proxy.rb:164:in  
`send' /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/active_record/associations/association_proxy.rb:164:in `with\_scope’  
/opt/local/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/active\_record/associations/association\_collection.rb:284:in  
`method_missing' /opt/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_view/helpers/form_helper.rb:628:in `send’  
/opt/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action\_view/helpers/form\_helper.rb:628:in  
`value_before_type_cast' /opt/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_view/helpers/form_helper.rb:616:in `value\_before\_type\_cast’  
/opt/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action\_view/helpers/form\_helper.rb:535:in  
`to_input_field_tag' /opt/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_view/helpers/form_helper.rb:358:in `text\_field’  
/opt/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action\_view/helpers/form\_helper.rb:713:in  
`send' /opt/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_view/helpers/form_helper.rb:713:in `text\_field’  
app/views/graph2/edit.html.erb:13:in  
`_run_erb_47app47views47graph247edit46html46erb' app/views/graph2/edit.html.erb:12:in `\_run\_erb\_47app47views47graph247edit46html46erb’  
app/views/graph2/edit.html.erb:3:in  
`_run_erb_47app47views47graph247edit46html46erb' /opt/local/bin/rdebug-ide:19:in `load’  
/opt/local/bin/rdebug-ide:19

/opt/local/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/active\_record/base.rb:1672:in  
`method_missing' /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/active_record/associations/association_collection.rb:288:in `send’  
/opt/local/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/active\_record/associations/association\_collection.rb:288:in  
`method_missing' /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/active_record/base.rb:1857:in `with\_scope’  
/opt/local/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/active\_record/associations/association\_proxy.rb:164:in  
`send' /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/active_record/associations/association_proxy.rb:164:in `with\_scope’  
/opt/local/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/active\_record/associations/association\_collection.rb:284:in  
`method_missing' /opt/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_view/helpers/form_helper.rb:628:in `send’  
/opt/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action\_view/helpers/form\_helper.rb:628:in  
`value_before_type_cast' /opt/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_view/helpers/form_helper.rb:616:in `value\_before\_type\_cast’  
/opt/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action\_view/helpers/form\_helper.rb:535:in  
`to_input_field_tag' /opt/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_view/helpers/form_helper.rb:358:in `text\_field’  
/opt/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action\_view/helpers/form\_helper.rb:713:in  
`send' /opt/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_view/helpers/form_helper.rb:713:in `text\_field’  
/opt/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action\_view/helpers/form\_helper.rb:317:in  
`fields_for' /opt/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_view/helpers/form_helper.rb:317:in `fields\_for’  
/opt/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action\_view/helpers/form\_helper.rb:253:in  
`form_for' /opt/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_view/base.rb:342:in `send’  
/opt/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action\_view/base.rb:342:in  
`execute' /opt/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_view/template_handlers/compilable.rb:29:in `send’  
/opt/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action\_view/template\_handlers/compilable.rb:29:in  
`render' /opt/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_view/template.rb:35:in `render’  
/opt/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action\_view/template.rb:22:in  
`render_template' /opt/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_view/base.rb:248:in `render\_file’  
/opt/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action\_controller/base.rb:1112:in  
`render_for_file' /opt/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/base.rb:845:in `render\_with\_no\_layout’  
/opt/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action\_controller/layout.rb:251:in  
`render_without_benchmark' /opt/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/benchmarking.rb:51:in `render\_without\_active\_scaffold’  
/opt/local/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active\_support/core\_ext/benchmark.rb:8:in  
`realtime' /opt/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/benchmarking.rb:51:in `render\_without\_active\_scaffold’  
vendor/plugins/active\_scaffold/lib/extensions/action\_controller\_rendering.rb:13:in  
`render' /opt/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/base.rb:1161:in `default\_render’  
/opt/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action\_controller/base.rb:1167:in  
`perform_action_without_filters' /opt/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/filters.rb:579:in `call\_filters’  
/opt/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action\_controller/filters.rb:572:in  
`perform_action_without_benchmark' /opt/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/benchmarking.rb:68:in `perform\_action\_without\_rescue’  
/opt/local/lib/ruby/1.8/benchmark.rb:293:in `measure' /opt/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/benchmarking.rb:68:in `perform\_action\_without\_rescue’  
/opt/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action\_controller/rescue.rb:201:in  
`perform_action_without_caching' /opt/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/caching/sql_cache.rb:13:in `perform\_action’  
/opt/local/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/active\_record/connection\_adapters/abstract/query\_cache.rb:33:in  
`cache' /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/active_record/query_cache.rb:8:in `cache’  
/opt/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action\_controller/caching/sql\_cache.rb:12:in  
`perform_action' /opt/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/base.rb:529:in `send’  
/opt/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action\_controller/base.rb:529:in  
`process_without_filters' /opt/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/filters.rb:568:in `process\_without\_session\_management\_support’  
/opt/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action\_controller/session\_management.rb:130:in  
`process' /opt/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/base.rb:389:in `process’  
/opt/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action\_controller/dispatcher.rb:149:in  
`handle_request' /opt/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/dispatcher.rb:107:in `dispatch’  
/opt/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action\_controller/dispatcher.rb:104:in  
`synchronize' /opt/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/dispatcher.rb:104:in `dispatch’  
/opt/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action\_controller/dispatcher.rb:120:in  
`dispatch_cgi' /opt/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/dispatcher.rb:35:in `dispatch’  
/opt/local/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel/rails.rb:76:in  
`process' /opt/local/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel/rails.rb:74:in `synchronize’  
/opt/local/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel/rails.rb:74:in  
`process' /opt/local/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:159:in `process\_client’  
/opt/local/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:158:in  
`each' /opt/local/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:158:in `process\_client’  
/opt/local/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:285:in  
`run' /opt/local/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:285:in `initialize’  
/opt/local/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:285:in  
`new' /opt/local/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:285:in `run’  
/opt/local/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:268:in  
`initialize' /opt/local/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:268:in `new’  
/opt/local/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:268:in  
`run' /opt/local/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel/configurator.rb:282:in `run’  
/opt/local/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel/configurator.rb:281:in  
`each' /opt/local/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel/configurator.rb:281:in `run’  
/opt/local/lib/ruby/gems/1.8/gems/mongrel-1.1.4/bin/mongrel\_rails:128:in  
`run' /opt/local/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel/command.rb:212:in `run’  
/opt/local/lib/ruby/gems/1.8/gems/mongrel-1.1.4/bin/mongrel\_rails:281  
/opt/local/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active\_support/dependencies.rb:503:in  
`load' /opt/local/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/dependencies.rb:503:in `load’  
/opt/local/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active\_support/dependencies.rb:355:in  
`new_constants_in' /opt/local/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/dependencies.rb:503:in `load’  
/opt/local/lib/ruby/gems/1.8/gems/rails-2.1.1/lib/commands/servers/mongrel.rb:64  
/opt/local/lib/ruby/site\_ruby/1.8/rubygems/custom\_require.rb:31:in  
`gem_original_require' /opt/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require’  
/opt/local/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active\_support/dependencies.rb:510:in  
`require' /opt/local/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/dependencies.rb:355:in `new\_constants\_in’  
/opt/local/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active\_support/dependencies.rb:510:in  
`require' /opt/local/lib/ruby/gems/1.8/gems/rails-2.1.1/lib/commands/server.rb:39 /opt/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem\_original\_require’  
/opt/local/lib/ruby/site\_ruby/1.8/rubygems/custom\_require.rb:31:in  
`require' script/server:3 /opt/local/lib/ruby/gems/1.8/gems/ruby-debug-ide-0.3.1/lib/ruby-debug.rb:96:in `debug\_load’  
/opt/local/lib/ruby/gems/1.8/gems/ruby-debug-ide-0.3.1/lib/ruby-debug.rb:96:in  
`main’  
/opt/local/lib/ruby/gems/1.8/gems/ruby-debug-ide-0.3.1/bin/rdebug-ide:76

/opt/local/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/active\_record/base.rb:1672:in  
`method_missing' /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/active_record/associations/association_collection.rb:288:in `send’  
/opt/local/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/active\_record/associations/association\_collection.rb:288:in  
`method_missing' /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/active_record/base.rb:1857:in `with\_scope’  
/opt/local/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/active\_record/associations/association\_proxy.rb:164:in  
`send' /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/active_record/associations/association_proxy.rb:164:in `with\_scope’  
/opt/local/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/active\_record/associations/association\_collection.rb:284:in  
`method_missing' /opt/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_view/helpers/form_helper.rb:628:in `send’  
/opt/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action\_view/helpers/form\_helper.rb:628:in  
`value_before_type_cast' /opt/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_view/helpers/form_helper.rb:616:in `value\_before\_type\_cast’  
/opt/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action\_view/helpers/form\_helper.rb:535:in  
`to_input_field_tag' /opt/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_view/helpers/form_helper.rb:358:in `text\_field’  
/opt/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action\_view/helpers/form\_helper.rb:713:in  
`send' /opt/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_view/helpers/form_helper.rb:713:in `text\_field’  
app/views/graph2/edit.html.erb:13:in  
`_run_erb_47app47views47graph247edit46html46erb' /opt/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_view/helpers/form_helper.rb:317:in `fields\_for’  
app/views/graph2/edit.html.erb:12:in  
`_run_erb_47app47views47graph247edit46html46erb' /opt/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_view/helpers/form_helper.rb:317:in `fields\_for’  
/opt/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action\_view/helpers/form\_helper.rb:253:in  
`form_for' app/views/graph2/edit.html.erb:3:in `\_run\_erb\_47app47views47graph247edit46html46erb’  
/opt/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action\_view/base.rb:342:in  
`send' /opt/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_view/base.rb:342:in `execute’  
/opt/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action\_view/template\_handlers/compilable.rb:29:in  
`send' /opt/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_view/template_handlers/compilable.rb:29:in `render’  
/opt/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action\_view/template.rb:35:in  
`render' /opt/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_view/template.rb:22:in `render\_template’  
/opt/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action\_view/base.rb:248:in  
`render_file' /opt/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/base.rb:1112:in `render\_for\_file’  
/opt/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action\_controller/base.rb:845:in  
`render_with_no_layout' /opt/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/layout.rb:251:in `render\_without\_benchmark’  
/opt/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action\_controller/benchmarking.rb:51:in  
`render_without_active_scaffold' /opt/local/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/core_ext/benchmark.rb:8:in `realtime’  
/opt/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action\_controller/benchmarking.rb:51:in  
`render_without_active_scaffold' vendor/plugins/active_scaffold/lib/extensions/action_controller_rendering.rb:13:in `render’  
/opt/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action\_controller/base.rb:1161:in  
`default_render' /opt/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/base.rb:1167:in `perform\_action\_without\_filters’  
/opt/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action\_controller/filters.rb:579:in  
`call_filters' /opt/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/filters.rb:572:in `perform\_action\_without\_benchmark’  
/opt/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action\_controller/benchmarking.rb:68:in  
`perform_action_without_rescue' /opt/local/lib/ruby/1.8/benchmark.rb:293:in `measure’  
/opt/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action\_controller/benchmarking.rb:68:in  
`perform_action_without_rescue' /opt/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/rescue.rb:201:in `perform\_action\_without\_caching’  
/opt/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action\_controller/caching/sql\_cache.rb:13:in  
`perform_action' /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/active_record/connection_adapters/abstract/query_cache.rb:33:in `cache’  
/opt/local/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/active\_record/query\_cache.rb:8:in  
`cache' /opt/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/caching/sql_cache.rb:12:in `perform\_action’  
/opt/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action\_controller/base.rb:529:in  
`send' /opt/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/base.rb:529:in `process\_without\_filters’  
/opt/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action\_controller/filters.rb:568:in  
`process_without_session_management_support' /opt/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/session_management.rb:130:in `process’  
/opt/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action\_controller/base.rb:389:in  
`process' /opt/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/dispatcher.rb:149:in `handle\_request’  
/opt/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action\_controller/dispatcher.rb:107:in  
`dispatch' /opt/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/dispatcher.rb:104:in `synchronize’  
/opt/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action\_controller/dispatcher.rb:104:in  
`dispatch' /opt/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/dispatcher.rb:120:in `dispatch\_cgi’  
/opt/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action\_controller/dispatcher.rb:35:in  
`dispatch' /opt/local/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel/rails.rb:76:in `process’  
/opt/local/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel/rails.rb:74:in  
`synchronize' /opt/local/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel/rails.rb:74:in `process’  
/opt/local/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:159:in  
`process_client' /opt/local/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:158:in `each’  
/opt/local/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:158:in  
`process_client' /opt/local/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:285:in `run’  
/opt/local/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:285:in  
`initialize' /opt/local/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:285:in `new’  
/opt/local/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:285:in  
`run' /opt/local/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:268:in `initialize’  
/opt/local/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:268:in  
`new' /opt/local/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:268:in `run’  
/opt/local/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel/configurator.rb:282:in  
`run' /opt/local/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel/configurator.rb:281:in `each’  
/opt/local/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel/configurator.rb:281:in  
`run' /opt/local/lib/ruby/gems/1.8/gems/mongrel-1.1.4/bin/mongrel_rails:128:in `run’  
/opt/local/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel/command.rb:212:in  
`run' /opt/local/lib/ruby/gems/1.8/gems/mongrel-1.1.4/bin/mongrel_rails:281 /opt/local/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/dependencies.rb:503:in `load’  
/opt/local/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active\_support/dependencies.rb:503:in  
`load' /opt/local/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/dependencies.rb:355:in `new\_constants\_in’  
/opt/local/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active\_support/dependencies.rb:503:in  
`load' /opt/local/lib/ruby/gems/1.8/gems/rails-2.1.1/lib/commands/servers/mongrel.rb:64 /opt/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem\_original\_require’  
/opt/local/lib/ruby/site\_ruby/1.8/rubygems/custom\_require.rb:31:in  
`require' /opt/local/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/dependencies.rb:510:in `require’  
/opt/local/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active\_support/dependencies.rb:355:in  
`new_constants_in' /opt/local/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/dependencies.rb:510:in `require’  
/opt/local/lib/ruby/gems/1.8/gems/rails-2.1.1/lib/commands/server.rb:39  
/opt/local/lib/ruby/site\_ruby/1.8/rubygems/custom\_require.rb:31:in  
`gem_original_require' /opt/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require’  
script/server:3  
/opt/local/lib/ruby/gems/1.8/gems/ruby-debug-ide-0.3.1/lib/ruby-debug.rb:96:in  
`debug_load' /opt/local/lib/ruby/gems/1.8/gems/ruby-debug-ide-0.3.1/lib/ruby-debug.rb:96:in `main’  
/opt/local/lib/ruby/gems/1.8/gems/ruby-debug-ide-0.3.1/bin/rdebug-ide:76  
/opt/local/bin/rdebug-ide:19:in `load’  
/opt/local/bin/rdebug-ide:19

Request

Parameters:

None

Show session dump

* * *

:csrf\_id: e40b12ec5ff840a756d4a271e5250ca9  
as:category:  
:list: {}

flash: !map:ActionController::Flash::FlashHash {}

Response

Headers:

{“cookie”=\>[],  
“Cache-Control”=\>“no-cache”}

---

<div class="post-metadata">

**Author:** ![greg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/71c47a/32.png) [@greg](https://www.ruby-forum.com/u/greg)\
**Post date:** [November 22, 2008, 4:01pm UTC](https://www.ruby-forum.com/t/whats-wrong-with-this-code-hitting-my-head-against-a-wall/153874/2 "2008-11-22T16:01:53Z")

</div>

On Nov 22, 11:56 am, “Greg H.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> :lines" be enough?  
> attr\_accessible is something completely different. The issue here is  
> that all update\_attributes does is for each key value pair it calls  
> your\_model.send(“#{key}=”, value). That’s fine for attributes, but  
> that means that what it’s passing to lines= is not an array of Line  
> items, but an array of hashes.  
> In rails 2.1 you just have to extract that array of hashes, turn it  
> into objects of the right type and then assign it to  
> your\_object.lines. There was talk of changing this in rails 2.2 but I  
> can’t remember what was done about it in the end.

Fred

---

<div class="post-metadata">

**Author:** ![greg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/71c47a/32.png) [@greg](https://www.ruby-forum.com/u/greg)\
**Post date:** [November 23, 2008, 12:51am UTC](https://www.ruby-forum.com/t/whats-wrong-with-this-code-hitting-my-head-against-a-wall/153874/3 "2008-11-23T00:51:32Z")

</div>

thanks for responding Frederick: So just to clarify you mean:

(a) I would have to do this in my controller in the “save” method right?  
(b) so anyone that anyone using Rails that has nested models in their  
views do have to do this too then? i.e. extract work in the  
controller? i.e. there’s no ability in Rails 2.1 with nested models  
to have the params perfectly auto-populated the models (i.e. parent  
model and it’s association models) out-of-the-box?

thanks again

On Sun, Nov 23, 2008 at 1:00 AM, Frederick C.

---

<div class="post-metadata">

**Author:** ![greg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/71c47a/32.png) [@greg](https://www.ruby-forum.com/u/greg)\
**Post date:** [November 23, 2008, 8:21am UTC](https://www.ruby-forum.com/t/whats-wrong-with-this-code-hitting-my-head-against-a-wall/153874/4 "2008-11-23T08:21:41Z")

</div>

PS. Actually I’ve just seen in this RailsCasts episode that Ryan  
seems to have a nested model controller that does translate the parent  
& child model data from the form to parent model and its association  
(child model). Am I missing something Frederick re whether you may  
have been wrong here?

Link = [#73 Complex Forms Part 1 - RailsCasts](http://railscasts.com/episodes/73-complex-forms-part-1)

On Sun, Nov 23, 2008 at 9:50 AM, Greg H.

---

<div class="post-metadata">

**Author:** ![greg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/71c47a/32.png) [@greg](https://www.ruby-forum.com/u/greg)\
**Post date:** [November 22, 2008, 12:57pm UTC](https://www.ruby-forum.com/t/whats-wrong-with-this-code-hitting-my-head-against-a-wall/153874/5 "2008-11-22T12:57:47Z")

</div>

ok, re “I’m just trying to load a set of options which doesn’t require  
tables (i.e. using tableless plugin)” I’ve got the View working now,  
however when I submit back I have an error as Rails tries to populate  
the association models. Any ideas - it’s like the parameter  
array/hash structure coming into Rails is fine, however when it tries  
to load the association data into the model for the associations it  
has a problem.

Is my model (graph\_options.rb) correct? Do I need to specify a  
specific “attr\_accessible :lines” here? Or should the “has\_many  
:lines” be enough?

------------- ERROR -----------  
ActiveRecord::AssociationTypeMismatch in Graph2Controller#save

Line(#19260340) expected, got HashWithIndifferentAccess(#9296710)

RAILS\_ROOT: /Users/greg/source/myequity  
Application Trace | Framework Trace | Full Trace

/opt/local/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/active\_record/associations/association\_proxy.rb:210:in  
`raise_on_type_mismatch' /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/active_record/associations/association_collection.rb:232:in`replace’  
/opt/local/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/active\_record/associations/association\_collection.rb:232:in  
`each' /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/active_record/associations/association_collection.rb:232:in`replace’  
/opt/local/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/active\_record/associations.rb:1156:in  
`lines=' /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/active_record/base.rb:2372:in`send’  
/opt/local/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/active\_record/base.rb:2372:in  
`attributes=' /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/active_record/base.rb:2371:in`each’  
/opt/local/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/active\_record/base.rb:2371:in  
`attributes=' /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/active_record/base.rb:2141:in`initialize’  
app/controllers/graph2\_controller.rb:22:in `new' app/controllers/graph2_controller.rb:22:in`save’  
/opt/local/bin/rdebug-ide:19:in `load’  
/opt/local/bin/rdebug-ide:19

Request  
Parameters:

{“commit”=\>“Create Graph”,  
“authenticity\_token”=\>“78f0a9ff834dbf09d2ea788e5174649cbc933bf9”,  
“graph\_options”=\>{“start\_date”=\>“August 22,  
2008”,  
“end\_date”=\>“Februar y 22,  
2009”,  
“label\_title”=\>“asdf”,  
“lines”=\>[{“foo”=\>“November 22,  
2008”,  
“calc\_type”=\>“manual calc”},  
{“foo”=\>“November 22,  
2008”,  
“calc\_type”=\>“manual calc”}],  
“granularity”=\>“1”,  
“chart\_type”=\>“1”}}

----- VIEW ----------

# Graph Options Selection

\<% form\_for :graph\_options, :url =\> {:action =\> ‘save’} do |f| %\>  
\<%= f.error\_messages %\>

```
<% @graph_options.lines.each do |line| %>
  <tr>
    <% fields_for "graph_options[lines][]",

```

@graph\_options.lines[0] do |fields| %\>

 \<% end %\> \<% end %\> 

| Graph Title: | \<%= f.text\_field :label\_title %\> |
| Start Date: | \<%= f.calendar\_date\_select :start\_date %\> |
| End Date: | \<%= f.calendar\_date\_select :end\_date %\> |
| Granularity (days): | \<%= f.text\_field :granularity %\> |
| Chart Type: | \<%= f.text\_field :chart\_type %\> |
| Calculation Type: \<%= fields.text\_field ‘calc\_type’ %\> | Calculation Type: \<%= fields.calendar\_date\_select 'foo' %\> |

\<%= submit\_tag ‘Create Graph’ %\>

\<% end %\>

------ CONTROLLER -------  
class Graph2Controller \< ApplicationController

def edit  
# Default parameters for form  
@graph\_options = GraphOptions.new  
@graph\_options.start\_date = Time.now.to\_date - 3.months  
@graph\_options.end\_date = Time.now.to\_date + 3.months  
@graph\_options.granularity = 1  
@graph\_options.lines.build  
@graph\_options.lines.build

```
# Testing ONly
@graph_options.chart_type = 1
@graph_options.lines[0].calc_type = "manual calc"
@graph_options.lines[1].calc_type = "auto calc"
@graph_options.lines[0].foo = Time.now.to_date
@graph_options.lines[1].foo = Time.now.to_date

```

end

def save  
@graph\_options = GraphOptions.new(params[:graph\_options])  
render :action =\> “edit” if !@graph\_options.valid?  
end

end

----------MODEL----------

class GraphOptions \< ActiveRecord::BaseWithoutTable  
column :label\_title, :string  
column :start\_date, :date  
column :end\_date, :date  
column :granularity, :integer  
column :chart\_type, :integer

#attr\_accessible :lines

has\_many :lines

validates\_presence\_of :label\_title  
validates\_numericality\_of :granularity, :chart\_type  
validates\_associated :lines

def validate  
errors.add(‘start\_date’, ‘is not in Date format’) if  
!start\_date.kind\_of?(Date)  
errors.add(‘end\_date’, ‘is not in Date format’) if  
!end\_date.kind\_of?(Date)  
end

end

class Line \< ActiveRecord::BaseWithoutTable

# attr\_accessible :calc\_type

column :calc\_type, :string  
column :foo, :date  
validates\_presence\_of :calc\_type  
end

On Sat, Nov 22, 2008 at 3:35 PM, Greg H.

---

<div class="post-metadata">

**Author:** ![greg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/71c47a/32.png) [@greg](https://www.ruby-forum.com/u/greg)\
**Post date:** [November 23, 2008, 11:58am UTC](https://www.ruby-forum.com/t/whats-wrong-with-this-code-hitting-my-head-against-a-wall/153874/6 "2008-11-23T11:58:52Z")

</div>

On Nov 23, 7:21 am, “Greg H.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> PS. Actually I’ve just seen in this RailsCasts episode that Ryan  
> seems to have a nested model controller that does translate the parent  
> & child model data from the form to parent model and its association  
> (child model). Am I missing something Frederick re whether you may  
> have been wrong here?
> 
> Link =[#73 Complex Forms Part 1 - RailsCasts](http://railscasts.com/episodes/73-complex-forms-part-1)

That’s one way of doing it, another is doing it in the controller (in  
your update & create methods as you suggested). But there isn’t  
anything built in, if you look at Ryan’s code he’s added a magic  
accessor to his project model that massages an array of hashes into an  
array of task objects. You do need to write that code and it has to  
go somewhere.

Fred

---

<div class="post-metadata">

**Author:** ![greg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/71c47a/32.png) [@greg](https://www.ruby-forum.com/u/greg)\
**Post date:** [November 23, 2008, 1:52pm UTC](https://www.ruby-forum.com/t/whats-wrong-with-this-code-hitting-my-head-against-a-wall/153874/7 "2008-11-23T13:52:00Z")

</div>

Sent from my iPhone

On 23 Nov 2008, at 12:38, “Greg H.”  
\<removed\_email\_address@domain.invalid

> wrote:

> oh, got it Frederick,
> 
> To be more self sufficient, how would I be able to confirm for myself  
> exactly what the Rails controller framework is looking for when it’s  
> trying to create models out of the param’s it gets (i.e. behind the  
> scenes before it gets to your code)?

Look at the code for update\_attributes in activerecord

Fred

---

<div class="post-metadata">

**Author:** ![greg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/71c47a/32.png) [@greg](https://www.ruby-forum.com/u/greg)\
**Post date:** [November 23, 2008, 10:15pm UTC](https://www.ruby-forum.com/t/whats-wrong-with-this-code-hitting-my-head-against-a-wall/153874/8 "2008-11-23T22:15:52Z")

</div>

thanks - got the auto-creation of nested models working!

Now I seem to be on the next challenge of getting decent validation  
error messages show on the view with the nested models 🙂 Seems to  
be somewhat discussed at  
[#75 Complex Forms Part 3 - RailsCasts](http://railscasts.com/episodes/75-complex-forms-part-3) but doesn’t  
seem to have a perfect solution. Will keep digging. If someone knows  
of the latest/nicest way to nicely get detailed validation messages  
appearing where it makes sense for a view with nested models I’d be  
very interested 🙂

thanks

On Sun, Nov 23, 2008 at 10:50 PM, Frederick C.

---

<div class="post-metadata">

**Author:** ![greg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/71c47a/32.png) [@greg](https://www.ruby-forum.com/u/greg)\
**Post date:** [November 23, 2008, 1:39pm UTC](https://www.ruby-forum.com/t/whats-wrong-with-this-code-hitting-my-head-against-a-wall/153874/9 "2008-11-23T13:39:06Z")

</div>

oh, got it Frederick,

To be more self sufficient, how would I be able to confirm for myself  
exactly what the Rails controller framework is looking for when it’s  
trying to create models out of the param’s it gets (i.e. behind the  
scenes before it gets to your code)?

If I had a way of confirming this then I could cement my understanding  
of why Ryan’s extra method made the difference (as an example).

Do you have to pretty much look at Rails code to have derived this  
understanding? Like it’s not even clear to me which rails tool is  
being used to recursively build the models out of the params, as it  
must get called in the rails code. Hope this makes sense.

Thanks again

On Sun, Nov 23, 2008 at 8:57 PM, Frederick C.
