Answer the question
In order to leave comments, you need to log in
How to link 2 tables in Rails?
Hello, there are 2 tables.
1. Doctor
's table 2. Patient's table
Abbreviated as follows
create_table "doctors", force: :cascade do |t|
t.string "email", default: "", null: false
t.string "doctor_first_name"
t.string "doctor_second_name"
end
create_table "users", force: :cascade do |t|
t.string "name"
t.string "surname"
t.integer "age"
t.boolean "status"
t.date "enter_date"
t.text "diagnoz"
t.integer "doctor_id"
t.string "doctor_first_name"
t.string "doctor_second_name"
end
<td><%= user.name %></td>
<td><%= user.surname %></td>
<td><%= user.age %></td>
<% if user.status == true %>
<td>Здоровый</td>
<% else %>
<td>Больной</td>
<% end %>
<td><%= user.enter_date %></td>
<td><%= user.doctor_first_name %></td>
<td><%= user.doctor_id %></td>
<td><%= user.diagnoz %></td>
Answer the question
In order to leave comments, you need to log in
not user.doctor_first_name
, but user.doctor.doctor_first_name
and you need to specify a link belongs_to :doctor
for the user model
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question