Hi,
I am currently reading the Rails Recipes book and like the chapter on
providing your own in_place_editor for enumerations / selects.
I understood so far, or I believe that I understood ;-), how to do
that
for a field that uses values only, like choosing from “red”, “black”,
“green”. What I fail to understand is how to chose from associated
objects?!
Consider the following example. A “Reader” has_one “Book”, the book
s/he
is currently reading. Both “Reader” and “Book” are model objects. How
would
you go about at view to make the current book selectable?
With above mentioned Rails Recipe “Making Your Own JavaScript Helper”
it
is trivial to make the IDs (book_id) selectable, but I would rather like
the
user to select from a list of book titles than from a list of book ids.
If I provide the in_place_editor with the ids and titles of the
available
book as select options it works on the surface (book titles can be
chosen,
ids are used for the update calls), but the current value displayed in
the
tag is still an id. And I believe that I have to provide the
in_place_editor
helper method with “:reader” and “:book_id”, because it uses it for the
update_url.
Providing a new parameter to the helper method for creating the
in_place_editor might work, but it seems that there is some stuff
happening
under the hood retrieving the original id when creating the instance
tag.
Would it be an option to overwrite the result? If so how to find which
attribute? tag.inspect returns pages of variables. What to look for?
Btw. What is the easiest way to open a referenced class, like
InstanceTag,
from within TextMate, when you don’t know what the source file is a
called?
Is a global search in the project the only option?
I am at loss here what to do without rewriting most of the existing
code
relevant to in_place_editors?
On the other hand though handling of associations in the view is also
absent in the generated scaffolds and I haven’t seen any support for
that in
any other view related topic. Am I doing something wrong and don’t
understand the Golden Path™? Isn’t choosing from associated objects
an
every day case?
Any help and insight is appreciated.
Thanks,
Mariano