Frage

a nested model is created with default records and values. users can edit the nested model from within parent.

The nested fields_for form allows editing of some values, not all, yet should display the values of the join table AND values of the related has_many :through table.

Cannot get the syntax right, notwithstanding <%= instance_variables %> does state that @jointables is a valid instance

<%= f.fields_for :jointables do |ff| %>
  <%= ff.number_field :quantity %>
  <%= :related_id %>
  <%= Related.where(['id = ?', @jointables.related_id]).first %>
<% end %>

Update getting the value of a variable is as follows:

<%= ff.object.related_id %>

Non-functioning variant for retrieving related value:

generates invalid input syntax for integer: "related_id"

War es hilfreich?

Lösung

So if the value can be retrieved, rails ought to know the existence of a relation and be able to fetch it, right?

<%= ff.object.related.name %>

Right.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top