There are two tables - Rubric and Question . One to many relationship. The task is to edit the Question with reference to Rubric . I am sampling from both tables. It is not entirely clear how to use data from headings to link them to a question.

  def edit @rubrics = Rubric.where(rubric_type: :question); @question = Question.find(params[:id]) end <%= render 'validation_errors', object: @question %> <%= form_for [:admin, @question], html: {multipart: true} do |f| %> <p> <%= f.label :title %> <%= f.text_field :title %> </p> <p> <%= f.label :question %> <%= f.trix_editor :question %> </p> <p> <%= f.label :answer %> <%= f.trix_editor :answer%> </p> <p> <%= f.label :created_at %> <%= f.label :created_at %> </p> <%= f.select :rubric %> <p> <%= f.submit %> </p> <% end %> 

    1 answer 1

    You can send rubrics to the view as you do - this is an acceptable option. And you can show rubrics in a select in the form like this:

     = f.collection_select :rubric_id, @rubrics, :id, :title, { prompt: 'Выберите рубрику' }, { class: 'select' } 

    Where:

    • rubric_id - the @question parameter with which we associate the given select;
    • @rubrics - collection, on which points of the select will be built;
    • :id - this field of collection elements will form the basis of the value of select items;
    • :title - from this field will build the names of your items.