Bug in create action if you include virtual fields in the column definition

4 views
Skip to first unread message

Soren

unread,
Feb 1, 2008, 8:45:16 PM2/1/08
to ActiveScaffold : Ruby on Rails plugin
Hi,

First of all - THANKS for a great piece of code. Truly helpful to get
things off the ground - and even as the final interface.

I have just started using the virtual column definitions, and today
encountered a create bug.

I have a company_controller - and in its model I have defined a method
like:

def total_investment_by_company
conditions = "company_id = '#{self.id}'"
Investment.find_by_conditions(conditions).sum {|
investment| investment.amount}
end

This works great for list actions etc etc, but when I create a new
element using the "Create New" I get the error log included below.

Is this indeed a BUG or did I goof it up ?

/S



Processing CompanyController#create (for 192.168.0.200 at 2008-02-01
17:41:55) [POST]
Session ID: 4d26902f509b967f63d9c960970d852f
Parameters: {"commit"=>"Create", "action"=>"create",
"controller"=>"company", "associated_id"=>"2",
"record"=>{"name"=>"xyz", "city"=>"", "www"=>"", "zip"=>"",
"contact"=>{"city"=>"", "name"=>"", "company"=>"", "skype"=>"",
"www"=>"", "zip"=>"", "title"=>"", "country"=>"", "im"=>"",
"mobile"=>"", "phone"=>"", "address"=>"", "email"=>""}, "country"=>"",
"phone"=>"", "fax"=>"", "address"=>"", "fund"=>{"name"=>"XXX",
"id"=>"2"}, "total_investment_by_company"=>"0"}}
Fund Columns (0.000395) SHOW FIELDS FROM funds
Contact Columns (0.000758) SHOW FIELDS FROM contacts
SQL (0.000061) BEGIN
Fund Load (0.000149) SELECT * FROM funds WHERE (funds.`id` = 2)
Investment Load (0.000198) SELECT * FROM investments WHERE
(company_id = '')
SQL (0.000061) ROLLBACK


NoMethodError (undefined method `total_investment_by_company=' for
#<Company:0x2b018f196728>):
/usr/lib64/ruby/gems/1.8/gems/activerecord-1.15.3/lib/
active_record/base.rb:1857:in `method_missing'
.//vendor/plugins/active_scaffold/lib/attribute_params.rb:106:in
`send'
.//vendor/plugins/active_scaffold/lib/attribute_params.rb:106:in
`update_record_from_params'
.//vendor/plugins/active_scaffold/lib/data_structures/
action_columns.rb:68:in `each'
.//vendor/plugins/active_scaffold/lib/data_structures/
action_columns.rb:55:in `each'
.//vendor/plugins/active_scaffold/lib/attribute_params.rb:49:in
`update_record_from_params'
.//vendor/plugins/active_scaffold/lib/actions/create.rb:73:in
`do_create'
/usr/lib64/ruby/gems/1.8/gems/activerecord-1.15.3/lib/
active_record/connection_adapters/abstract/database_statements.rb:
59:in `transaction'
/usr/lib64/ruby/gems/1.8/gems/activerecord-1.15.3/lib/
active_record/transactions.rb:95:in `transaction'
.//vendor/plugins/active_scaffold/lib/actions/create.rb:72:in
`do_create'
.//vendor/plugins/active_scaffold/lib/actions/create.rb:28:in
`create'
/usr/lib64/ruby/gems/1.8/gems/actionpack-1.13.3/lib/
action_controller/base.rb:1095:in `send'
/usr/lib64/ruby/gems/1.8/gems/actionpack-1.13.3/lib/
action_controller/base.rb:1095:in `perform_action_without_filters'
/usr/lib64/ruby/gems/1.8/gems/actionpack-1.13.3/lib/
action_controller/filters.rb:632:in `call_filter'
/usr/lib64/ruby/gems/1.8/gems/actionpack-1.13.3/lib/
action_controller/filters.rb:638:in `call_filter'
/usr/lib64/ruby/gems/1.8/gems/actionpack-1.13.3/lib/
action_controller/filters.rb:438:in `call'
/usr/lib64/ruby/gems/1.8/gems/actionpack-1.13.3/lib/
action_controller/filters.rb:637:in `call_filter'
/usr/lib64/ruby/gems/1.8/gems/actionpack-1.13.3/lib/
action_controller/filters.rb:638:in `call_filter'
/usr/lib64/ruby/gems/1.8/gems/actionpack-1.13.3/lib/
action_controller/filters.rb:438:in `call'
/usr/lib64/ruby/gems/1.8/gems/actionpack-1.13.3/lib/
action_controller/filters.rb:637:in `call_filter'
/usr/lib64/ruby/gems/1.8/gems/actionpack-1.13.3/lib/
action_controller/filters.rb:634:in `call_filter'
/usr/lib64/ruby/gems/1.8/gems/actionpack-1.13.3/lib/
action_controller/filters.rb:638:in `call_filter'
/usr/lib64/ruby/gems/1.8/gems/actionpack-1.13.3/lib/
action_controller/filters.rb:438:in `call'
/usr/lib64/ruby/gems/1.8/gems/actionpack-1.13.3/lib/
action_controller/filters.rb:637:in `call_filter'
/usr/lib64/ruby/gems/1.8/gems/actionpack-1.13.3/lib/
action_controller/filters.rb:634:in `call_filter'
/usr/lib64/ruby/gems/1.8/gems/actionpack-1.13.3/lib/
action_controller/filters.rb:638:in `call_filter'
/usr/lib64/ruby/gems/1.8/gems/actionpack-1.13.3/lib/
action_controller/filters.rb:438:in `call'
/usr/lib64/ruby/gems/1.8/gems/actionpack-1.13.3/lib/
action_controller/filters.rb:637:in `call_filter'
/usr/lib64/ruby/gems/1.8/gems/actionpack-1.13.3/lib/
action_controller/filters.rb:638:in `call_filter'
/usr/lib64/ruby/gems/1.8/gems/actionpack-1.13.3/lib/
action_controller/filters.rb:438:in `call'
/usr/lib64/ruby/gems/1.8/gems/actionpack-1.13.3/lib/
action_controller/filters.rb:637:in `call_filter'
/usr/lib64/ruby/gems/1.8/gems/actionpack-1.13.3/lib/
action_controller/filters.rb:638:in `call_filter'
/usr/lib64/ruby/gems/1.8/gems/actionpack-1.13.3/lib/
action_controller/filters.rb:438:in `call'
/usr/lib64/ruby/gems/1.8/gems/actionpack-1.13.3/lib/
action_controller/filters.rb:637:in `call_filter'
/usr/lib64/ruby/gems/1.8/gems/actionpack-1.13.3/lib/
action_controller/filters.rb:638:in `call_filter'
/usr/lib64/ruby/gems/1.8/gems/actionpack-1.13.3/lib/
action_controller/filters.rb:438:in `call'
/usr/lib64/ruby/gems/1.8/gems/actionpack-1.13.3/lib/
action_controller/filters.rb:637:in `call_filter'
/usr/lib64/ruby/gems/1.8/gems/actionpack-1.13.3/lib/
action_controller/filters.rb:638:in `call_filter'
/usr/lib64/ruby/gems/1.8/gems/actionpack-1.13.3/lib/
action_controller/filters.rb:438:in `call'
/usr/lib64/ruby/gems/1.8/gems/actionpack-1.13.3/lib/
action_controller/filters.rb:637:in `call_filter'
/usr/lib64/ruby/gems/1.8/gems/actionpack-1.13.3/lib/
action_controller/filters.rb:638:in `call_filter'
/usr/lib64/ruby/gems/1.8/gems/actionpack-1.13.3/lib/
action_controller/filters.rb:449:in `call'
/usr/lib64/ruby/gems/1.8/gems/actionpack-1.13.3/lib/
action_controller/filters.rb:637:in `call_filter'
/usr/lib64/ruby/gems/1.8/gems/actionpack-1.13.3/lib/
action_controller/filters.rb:619:in `perform_action_without_benchmark'
/usr/lib64/ruby/gems/1.8/gems/actionpack-1.13.3/lib/
action_controller/benchmarking.rb:66:in
`perform_action_without_rescue'
/usr/lib64/ruby/1.8/benchmark.rb:293:in `measure'
/usr/lib64/ruby/gems/1.8/gems/actionpack-1.13.3/lib/
action_controller/benchmarking.rb:66:in
`perform_action_without_rescue'
/usr/lib64/ruby/gems/1.8/gems/actionpack-1.13.3/lib/
action_controller/rescue.rb:83:in `perform_action'
/usr/lib64/ruby/gems/1.8/gems/actionpack-1.13.3/lib/
action_controller/base.rb:430:in `send'
/usr/lib64/ruby/gems/1.8/gems/actionpack-1.13.3/lib/
action_controller/base.rb:430:in `process_without_filters'
/usr/lib64/ruby/gems/1.8/gems/actionpack-1.13.3/lib/
action_controller/filters.rb:624:in
`process_without_session_management_support'
/usr/lib64/ruby/gems/1.8/gems/actionpack-1.13.3/lib/
action_controller/session_management.rb:114:in `process'
/usr/lib64/ruby/gems/1.8/gems/actionpack-1.13.3/lib/
action_controller/base.rb:330:in `process'
/usr/lib64/ruby/gems/1.8/gems/rails-1.2.3/lib/dispatcher.rb:41:in
`dispatch'
/usr/lib64/ruby/gems/1.8/gems/mongrel-0.3.13.4/lib/mongrel/
rails.rb:84:in `process'
/usr/lib64/ruby/1.8/sync.rb:229:in `synchronize'
/usr/lib64/ruby/gems/1.8/gems/mongrel-0.3.13.4/lib/mongrel/
rails.rb:83:in `process'
/usr/lib64/ruby/gems/1.8/gems/mongrel-0.3.13.4/lib/mongrel.rb:
580:in `process_client'
/usr/lib64/ruby/gems/1.8/gems/mongrel-0.3.13.4/lib/mongrel.rb:
579:in `each'
/usr/lib64/ruby/gems/1.8/gems/mongrel-0.3.13.4/lib/mongrel.rb:
579:in `process_client'
/usr/lib64/ruby/gems/1.8/gems/mongrel-0.3.13.4/lib/mongrel.rb:
686:in `run'
/usr/lib64/ruby/gems/1.8/gems/mongrel-0.3.13.4/lib/mongrel.rb:
686:in `initialize'
/usr/lib64/ruby/gems/1.8/gems/mongrel-0.3.13.4/lib/mongrel.rb:
686:in `new'
/usr/lib64/ruby/gems/1.8/gems/mongrel-0.3.13.4/lib/mongrel.rb:
686:in `run'
/usr/lib64/ruby/gems/1.8/gems/mongrel-0.3.13.4/lib/mongrel.rb:
673:in `initialize'
/usr/lib64/ruby/gems/1.8/gems/mongrel-0.3.13.4/lib/mongrel.rb:
673:in `new'
/usr/lib64/ruby/gems/1.8/gems/mongrel-0.3.13.4/lib/mongrel.rb:
673:in `run'
/usr/lib64/ruby/gems/1.8/gems/mongrel-0.3.13.4/lib/mongrel/
configurator.rb:267:in `run'
/usr/lib64/ruby/gems/1.8/gems/mongrel-0.3.13.4/lib/mongrel/
configurator.rb:266:in `each'
/usr/lib64/ruby/gems/1.8/gems/mongrel-0.3.13.4/lib/mongrel/
configurator.rb:266:in `run'
/usr/lib64/ruby/gems/1.8/gems/mongrel-0.3.13.4/bin/mongrel_rails:
127:in `run'
/usr/lib64/ruby/gems/1.8/gems/mongrel-0.3.13.4/lib/mongrel/
command.rb:211:in `run'
/usr/lib64/ruby/gems/1.8/gems/mongrel-0.3.13.4/bin/mongrel_rails:
231
/usr/lib64/ruby/gems/1.8/gems/activesupport-1.4.2/lib/
active_support/dependencies.rb:488:in `load'
/usr/lib64/ruby/gems/1.8/gems/activesupport-1.4.2/lib/
active_support/dependencies.rb:488:in `load'
/usr/lib64/ruby/gems/1.8/gems/activesupport-1.4.2/lib/
active_support/dependencies.rb:342:in `new_constants_in'
/usr/lib64/ruby/gems/1.8/gems/activesupport-1.4.2/lib/
active_support/dependencies.rb:488:in `load'
/usr/lib64/ruby/gems/1.8/gems/rails-1.2.3/lib/commands/servers/
mongrel.rb:60
/usr/lib64/ruby/vendor_ruby/1.8/rubygems/custom_require.rb:27:in
`gem_original_require'
/usr/lib64/ruby/vendor_ruby/1.8/rubygems/custom_require.rb:27:in
`require'
/usr/lib64/ruby/gems/1.8/gems/activesupport-1.4.2/lib/
active_support/dependencies.rb:495:in `require'
/usr/lib64/ruby/gems/1.8/gems/activesupport-1.4.2/lib/
active_support/dependencies.rb:342:in `new_constants_in'
/usr/lib64/ruby/gems/1.8/gems/activesupport-1.4.2/lib/
active_support/dependencies.rb:495:in `require'
/usr/lib64/ruby/gems/1.8/gems/rails-1.2.3/lib/commands/server.rb:
39
/usr/lib64/ruby/vendor_ruby/1.8/rubygems/custom_require.rb:27:in
`gem_original_require'
/usr/lib64/ruby/vendor_ruby/1.8/rubygems/custom_require.rb:27:in
`require'
script/server:3


Rendering /usr/lib64/ruby/gems/1.8/gems/actionpack-1.13.3/lib/
action_controller/templates/rescues/layout.rhtml (500 Internal Error)

Sergio Cambra

unread,
Feb 2, 2008, 5:53:33 AM2/2/08
to actives...@googlegroups.com
El Sábado, 2 de Febrero de 2008, Soren escribió:
> Hi,
>
> First of all - THANKS for a great piece of code. Truly helpful to get
> things off the ground - and even as the final interface.
>
> I have just started using the virtual column definitions, and today
> encountered a create bug.
>
> I have a company_controller - and in its model I have defined a method
> like:
>
> def total_investment_by_company
> conditions = "company_id = '#{self.id}'"
> Investment.find_by_conditions(conditions).sum {|
> investment| investment.amount}
> end
>
> This works great for list actions etc etc, but when I create a new
> element using the "Create New" I get the error log included below.
>
> Is this indeed a BUG or did I goof it up ?
>

It's not a bug, this is the error you get:

> NoMethodError (undefined method `total_investment_by_company=' for
> #<Company:0x2b018f196728>):

You are defined a method to query total_investment_by_company, but you must
define a method to assign a value too: total_investment_by_company=

MrBa...@googlemail.com

unread,
Feb 4, 2008, 4:09:42 AM2/4/08
to ActiveScaffold : Ruby on Rails plugin
If you do not want to show that column at all in create view you can
exclude that attribute from the create columns list.

I would think there is no need to set a calculated attribute in the
model....

--
Volker

Soren

unread,
Feb 4, 2008, 2:50:02 PM2/4/08
to ActiveScaffold : Ruby on Rails plugin
Exactly

Use config.columns.list to control the inclusion of the field in your
list action,

or/and use config.columns.exclude to remove it from your other
actions.

config.list.columns << :total_investment_by_company

/S

On Feb 4, 1:09 am, "MrBana...@googlemail.com"
Reply all
Reply to author
Forward
0 new messages