Hi Lasse,
thanks for repying.
I have the same for the controller and the view, not sure about the
action.
This is how set about to get there:
% script/generate scaffold_for_view supplier name:string street:string
streetnumber:decimal
zipcode:decimal city:string mail:string phone:string vat:string
% rake db:migrate
% gem sources -a http://gemcutter.org
% sudo gem install view_mapper
% ./script/plugin install git://github.com/rails/auto_complete.git
I add to the supplier model:
has_many :expenses
% script/generate scaffold_for_view expense title:string
amount:decimal payment:string
description:string category:string subcategory:string date:date –
view belongs_to_auto_complete:supplier
That’s it. When I add some suppliers, I can autocomplete them in the
expense form, but when I use a name that’s not found, it doesn’t get
submitted.
The output of the server script is:
Processing ExpensesController#create (for 127.0.0.1 at 2010-03-30
11:26:31) [POST]
Parameters: {“commit”=>“Create”, “expense”=>{“date(1i)”=>“2010”,
“subcategory”=>“test”, “category”=>“test”, “date(2i)”=>“3”,
“title”=>“Test”, “date(3i)”=>“29”, “amount”=>“0.0”, “payment”=>“test”,
“supplier_name”=>“tester”, “description”=>“test”},
“authenticity_token”=>“c845768fead94721c294f12ebc6f3b508e031398”}
Supplier Load (0.2ms) SELECT * FROM “suppliers” WHERE
(“suppliers”.“name” = ‘tester’) LIMIT 1
Rendering template within layouts/expenses
Rendering expenses/new
Rendered expenses/_form (78.5ms)
Completed in 183ms (View: 144, DB: 0) | 200 OK [http://localhost/
expenses]
Processing ExpensesController#create (for 127.0.0.1 at 2010-03-30
11:26:39) [POST]
Parameters: {“commit”=>“Create”, “expense”=>{“date(1i)”=>“2010”,
“subcategory”=>“test”, “category”=>“test”, “date(2i)”=>“3”,
“title”=>“Test”, “date(3i)”=>“29”, “amount”=>“0.01”,
“payment”=>“test”, “supplier_name”=>“”, “description”=>“test”},
“authenticity_token”=>“c845768fead94721c294f12ebc6f3b508e031398”}
Supplier Load (0.2ms) SELECT * FROM “suppliers” WHERE
(“suppliers”.“name” = ‘’) LIMIT 1
Expense Create (34.4ms) INSERT INTO “expenses” (“category”,
“subcategory”, “created_at”, “title”, “updated_at”, “amount”, “date”,
“payment”, “supplier_id”, “description”) VALUES(‘test’, ‘test’,
‘2010-03-30 09:26:39’, ‘Test’, ‘2010-03-30 09:26:39’, 0.01,
‘2010-03-29’, ‘test’, NULL, ‘test’)
Redirected to #Expense:0x103d8e920
Completed in 52ms (DB: 35) | 302 Found [http://localhost/expenses]
In the first block, the name is still there (tester), but in the
second, it isn’t. Why would that be?
Many thanks,
Wim