Forum: Ruby on Rails Need help .. Rails Recipes, in_place_editor, selecting assoc

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
838869251cf09420cc80a9e008adddc1?d=identicon&s=25 Mariano Kamp (Guest)
on 2006-03-18 16:50
(Received via mailing list)

  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
for a field that uses values only, like choosing from "red", "black",
"green". What I fail to understand is how to chose from associated

  Consider the following example. A "Reader" has_one "Book", the book
is currently reading. Both "Reader" and "Book" are model objects. How
you go about at view to make the current book selectable?

  With above mentioned Rails Recipe "Making Your Own JavaScript Helper"
is trivial to make the IDs (book_id) selectable, but I would rather like
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
book as select options it works on the surface (book titles can be
ids are used for the update calls), but the current value displayed in
tag is still an id. And I believe that I have to provide the
helper method with ":reader" and ":book_id", because it uses it for the

  Providing a new parameter to the helper method for creating the
in_place_editor might work, but it seems that there is some stuff
under the hood retrieving the original id when creating the instance
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
from within TextMate, when you don't know what the source file is a
Is a global search in the project the only option?

  I am at loss here what to do without rewriting most of the existing
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(tm)? Isn't choosing from associated objects
every day case?

  Any help and insight is appreciated.

838869251cf09420cc80a9e008adddc1?d=identicon&s=25 Mariano Kamp (Guest)
on 2006-03-19 16:49
(Received via mailing list)
I am still looking for help ;-)

Regarding the question if rails turns a blind eye on associations
in the view or me on the rails doc, I came across the following in the
documentation of ActionView::Helpers::ActiveRecordHelper (

[..] The most far-reaching is the form method that creates a complete
for all the basic content types of the record --> (not associations or
aggregations, though) <--. [..]

So the rails helpers don't provide support for assocations, right? Any
why that is?

Just out of curiosity. Imagine I would be capable and willing to
the "missing" feature. How would I go about this and what would be the
idea about doing this following the Golden Path(tm)?

>From my point of view a) an identifier/label needs to be identified in the
associated model, e.g. "name" of the associated "Book". My first guess
that it belongs to the controller/view not the model of "Reader".

  belongs_to :book

  in_place_edit_for :reader, :name
  in_place_association_edit_for :reader, :book   # <----------------

The following information should be derived:
id field = book_id (as a default, otherwise the attribute would need to
label field = (as a default, otherwise the attribute would
need to
be specified)
I am not sure if the label field is necessary at all, because the
just needs to know which field to update, right? It might only be
if the view only handles the lables. More on that below.

In the view:

  in_place_select_association_editor_field :reader, :book

I believe it would be ok to make the label ( unique. That
would be
convenient, because then "id" and "label/name" can be used
i.e. just one, the lagel, need to be used. Otherwise all ids and
labels/names of "Book" needs to be known in the view.

The view should display a picklist with all the labels in it and
on either using unique labels just have a label picked or when using ids
labels set the id in the view.

This topic is locked and can not be replied to.