Answer the question
In order to leave comments, you need to log in
How to add a new field to a Ruby On Rails model?
In general, there is a model. Created a migration like rails g migration AddEmploymentToGuests. A field was added to the database added an input to guests#new to enter this field here is the guests#new page itself
<%= form_for(@guest) do |f| %>
<% if @guest.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@guest.errors.count, "error") %> prohibited this guest from being saved:</h2>
<ul>
<% @guest.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<input placeholder= "Ваше имя" type="text", name= "guest[first_name]", id="guest_first_name" required>
</div>
<div class="field">
<input placeholder = "Ваша фамилия" type="text", name = "guest[second_name]", id = "guest_second_name" required>
</div>
<div class="field">
<input placeholder = "Email" type="email" name = "guest[email]", id ="guest_email" required>
</div>
<div class="field">
<input placeholder = "Номер телефона" type="text" required name="guest[phone_number]" id ="guest_phone_number">
</div>
<%= f.text_field :employment %>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
raw_attributes:
id: 16
first_name: asd
second_name: asda
email: [email protected]
phone_number: '8123'
created_at: '2016-03-06 15:54:37.993403'
updated_at: '2016-03-06 15:54:37.993403'
employment:
Answer the question
In order to leave comments, you need to log in
Most likely it is necessary to add to the allowed parameters (permit params) in the controller.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question