Rails - представления с вложенными атрибутами не отображаются - PullRequest
0 голосов
/ 28 июня 2019

Я использую таблицу соединений и вложенные атрибуты для сбора списка интересов инвесторов в отдельной таблице для профилей инвесторов.По некоторым причинам мое представление пустое и не показывает текстовое поле investor_interest для обновления.Можете ли вы найти это почему?Мой код ниже.

investor_profile.rb

class InvestorProfile < ApplicationRecord
  belongs_to :user

  has_many :investor_profile_interests
  has_many :investor_interests, through: :investor_profile_interests

  accepts_nested_attributes_for :investor_profile_interests

end

investor_interest.rb

class InvestorInterest < ApplicationRecord
  has_many :investor_profile_interests
  has_many :investor_profiles, through: :investor_profile_interests
end

investor_profile_interest.rb

class InvestorProfileInterest < ApplicationRecord
  belongs_to :investor_profile
  belongs_to :investor_interest

end

контроллер профиля инвестора

def new
  @investor_profile = InvestorProfile.new
end

просмотров

<%= form_with model: @investor_profile, class: 'form new-profile-form' do |f| %>
   <div class="field">
      <%= f.fields_for :investor_profile_interests do |test| %>
        <%= test.text_field :investor_interest %>
      <% end %>
   </div>
  <div class="field">
      <%= f.submit 'Submit', class: 'button is-primary is-normal' %>
   </div>
<% end %>

1 Ответ

1 голос
/ 28 июня 2019

В новом методе build investor_profile_interests -

def new
  @investor_profile = InvestorProfile.new
  @investor_profile.investor_profile_interests.build
end

...