Resolvi o problema da busca. Testa lá em materials na porta 3007. Só a preciss de 2 coisas agora: ajeitar o data picker e tirar aquelas opcoes da busca. Abs
2011/10/10 Cláudio Forain <claudi...@gmail.com>:
I just corrected the following line from:
conf.columns[:document].includes = {:document => :course}
To:
conf.columns[:course].includes = {:document => :course}
And everything went smoothly
Anyway, now my problem is tha I would like that search field to be a
:search (with a dropdown) and not a :text (which it is now). So I
edited app/helpers/materials_helper.rb to populate the dropdown:
def course_search_column(record, input_name)
select :record, :course, options_for_select(Material.course),
{:include_blank => as_('-select-')}, input_name
end
Using that, trying to search gives me the following error:
ActionView::Template::Error (undefined method `course' for
#<Class:0x00000003f41520>):
4: <label for="<%= "search_#{column.name}" %>"><%=
column.label %></label>
5: </dt>
6: <dd>
7: <%= active_scaffold_search_for(column) %>
8: </dd>
9: </dl>
10: </li>
app/helpers/materials_helper.rb:4:in `course_search_column'
It shoud work since now Material has the course field delegated for
document, and if I run the application console (using rails console),
I get:
irb(main):001:0> material = Material.find(123)
=> #<Material id: 123, discipline_id: 5, document_id: 75, user_id: 35,
created_at: "2011-09-27 12:29:11", updated_at: "2011-09-28 15:02:11">
irb(main):002:0> material.course
=> #<Course id: 27, name: "1 Medio Regular - Manhã", code: "1 MEDREG-M">
Which means that material.course is a viable "method" . But maybe the
helper is in a "lower" scope than the model, which means that tthe :
delegate method won't work while in the helper. Any help will be
greatly appreciated.
PS: I will try the :has_one :through approach in a while.
2011/10/10 Cláudio Forain <claudi...@gmail.com>:
def course_search_column(record, input_name)
select :record, :course, options_for_select(Course.all.collect {
|c| [c.name, c.name] }), {:include_blank => as_('-select-')},
input_name
end
Everything worked as expected. Thanks for everything.
2011/10/10 Cláudio Forain <claudi...@gmail.com>: