form_for with same attributes for different year

22 views Asked by At

trying to implement a form_for with different years having the same input. I have two tables: Position (empty one) and PositionSteps (with year / company_name / position_title)

class Position < ApplicationRecord
  belongs_to :user

  has_many :position_steps, dependent: :destroy
end

class PositionStep < ApplicationRecord
  belongs_to :position

  validates_uniqueness_of :year
end

For exemple, a person have to indicate the the position and the company he works for. The first line is based on current information :

  • 2020 Google Sales (autocomplete with current info - that can be changed)

  • 2021 Google Head of sales

  • 2022 Facebook Head of marketing

        <%= form_for @score do |f| %>
         <div class="form-group">
           <%= f.date_field :year, value: @default_year, class: "form-control" %>
           <%= f.text_field :company_name, value: @default_company_name, class: "form-control" %>
           <%= f.text_field :position_title, value: @default_position_title, class: "form-control" %>
         </div>
    
         <div class="form-group">
           <%= f.date_field :year, class: "form-control" %>
           <%= f.text_field :company_name, class: "form-control" %> 
           <%= f.text_field :position_title, class: "form-control" %>
         </div>
    
         <div class="form-group">
           <%= f.date_field :year, class: "form-control" %>
           <%= f.text_field :company_name, class: "form-control" %> 
           <%= f.text_field :position_title, class: "form-control" %> 
         </div>
    
         <%= f.submit "Validate", class: 'btn' %>
       <% end %>
    

Not really sure about the way to implement my form in my edit page and ta save the data the user will add in my new table

Thanks for your help

0

There are 0 answers