Y
Y
yuharu2016-12-05 15:08:01
Ruby on Rails
yuharu, 2016-12-05 15:08:01

Adding a selection of existing records from another db table to the current one?

I can't figure out how, in the form of creating an entry in the albums table, you can add options for selecting groups from the corresponding model.
6c60b424f21b47ae9626b22a84720f67.jpgb533a132b5b642599ffdbd97cb9e0129.jpg421bafa9262f4558921911eaa4174126.jpgc1868fdedbc246f7b27de9c6c409b191.jpg

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nikita, 2016-12-05
@yuharu

It would be more convenient if you published the code of your view, but if I understand you correctly, then something like this:

= form_for(@album) do |f|
  = f.label :name
  = f.text_field :name

  = f.label :release_year
  = f.number_field :release_year

  = f.label :amount_of_member
  = f.number_field :amount_of_member

  = f.label :band
  = f.collection_select :band_id, Band.all, :id, :name, prompt: 'Select a Band'

The same thing with songs, only you make a selector for albums.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question