Hi,
Ive followed the pets/people ajax_scaffold example without any problem.
I have a table documents and each document has a category. In the
documents table i have a field called category_id. So in the documents
grif i want to display the corresponding catgory name and when it comes
to adding a new category or editing the have a drop down list to select
from.
category.rb
require ''ajax_scaffold''
class Category < ActiveRecord::Base
belongs_to :document
@scaffold_columns = [
AjaxScaffold::ScaffoldColumn.new(self, { :name => "name" })
]
end
document.rb
require ''ajax_scaffold''
class Document < ActiveRecord::Base
has_one :category
@scaffold_columns = [
AjaxScaffold::ScaffoldColumn.new(self, { :name => "name" }),
AjaxScaffold::ScaffoldColumn.new(self, { :name =>
"description"
}),
AjaxScaffold::ScaffoldColumn.new(self, { :name => "size" }),
AjaxScaffold::ScaffoldColumn.new(self, { :name => "location"
}),
AjaxScaffold::ScaffoldColumn.new(self, { :name => "Cat",
:eval => "document.category.name", :sortable => false })
]
end
_form.rhtml
<div class="form-element">
<label for="document_category">Category</label>
<%= select ''document'', ''category_id'' ,
Document.find_{[p.id ] } %>
</div>
documents_controller.rb
@paginator, @documents = paginate(:documents, :order => @sort_by,
:include => :category, :per_page => default_per_page)
I keep getting the following error:
ActiveRecord::StatementInvalid in DocumentsController#component
Mysql::Error: #42S22Unknown column ''categories.document_id'' in
''on
clause'': SELECT COUNT(DISTINCT documents.id) FROM documents LEFT OUTER
JOIN categories ON categories.document_id = documents.id
Can anyone help me and point out where i am going wrong?
--
Posted via http://www.ruby-forum.com/.