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


#1

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” 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:insend’
/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:inwith_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:inwith_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:insend’
/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:invalue_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:intext_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:intext_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:inload’
/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:insend’
/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:inwith_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:inwith_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:insend’
/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:invalue_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:intext_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:intext_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:infields_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:insend’
/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:insend’
/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:inrender’
/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:inrender_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:inrender_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:inrender_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:inrender_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:indefault_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:incall_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:inperform_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:inperform_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:inperform_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:incache’
/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:insend’
/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:inprocess_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:inprocess’
/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:indispatch’
/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:indispatch’
/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:indispatch’
/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:insynchronize’
/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:inprocess_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:inprocess_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:ininitialize’
/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:inrun’
/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:innew’
/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:inrun’
/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:inrun’
/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:inrun’
/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:inload’
/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:inload’
/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:inrequire’
/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:innew_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:ingem_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:indebug_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:insend’
/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:inwith_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:inwith_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:insend’
/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:invalue_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:intext_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:intext_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:infields_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:infields_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:inexecute’
/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:inrender’
/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:inrender_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:inrender_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:inrender_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:inrealtime’
/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:inrender’
/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:inperform_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:inperform_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:inmeasure’
/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:inperform_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:incache’
/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:inperform_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:inprocess_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:inprocess’
/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:inhandle_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:insynchronize’
/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:indispatch_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:inprocess’
/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:inprocess’
/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:ineach’
/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:inrun’
/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:innew’
/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:ininitialize’
/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:inrun’
/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:ineach’
/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:inrun’
/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:inload’
/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:innew_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:ingem_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:inrequire’
/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:inrequire’
/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:inrequire’
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:inmain’
/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”}


#2

On Nov 22, 11:56 am, “Greg H.” 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


#3

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.


#4

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 = http://railscasts.com/episodes/73-complex-forms-part-1

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


#5

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:inreplace’
/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:inreplace’
/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:insend’
/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:ineach’
/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:ininitialize’
app/controllers/graph2_controller.rb:22:in new' app/controllers/graph2_controller.rb:22:insave’
/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.


#6

On Nov 23, 7:21 am, “Greg H.” 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 =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


#7

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


#8

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 :slight_smile: Seems to
be somewhat discussed at
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 :slight_smile:

thanks

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


#9

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.