我想從另一個表中添加一個字段。這些表格已經與連接表和模型相匹配。 視圖索引可以是dipayed,它可以很好地工作。從另一個連接表添加字段
<%= @something.map(&:name).join(", ") %>
可能有人建議如何將字段添加到"new"/"edit"
什麼進入"form"
?
需要文本字段或「用戶」的完整詳細信息,例如姓名,地址等。非常感謝代碼輸入的建議。
這個使用的代碼:model:user,appointment,view/_form_for appointment。我正在嘗試將用戶和患者添加到預約表中,但似乎相當複雜。
attr_accessible :email, :password, :password_confirmation,
:remember_me, :dob, :first_name, :last_name, :gender, :doctor,
:pps_no, :specialisation_id, :roles, :roles_id, :roles_name,
:appointments, :appointments_id
# attr_accessible :title, :body
has_many :appointments, :through => :users_appointments
has_many :users_appointments
has_and_belongs_to_many :specialisations
has_many :roles, :through => :roles_users
has_many :roles_users
<%= form_for(@appointment) do |f| %>
<% if @appointment.errors.any?> %>
<div id="error_explanation">
<h2>
<%= pluralize(@appointment.errors.count, "error") %> prohibited this appointment from being saved:
</h2>
<ul>
<% @appointment.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :date_time %><br />
<%= f.datetime_select :date_time %>
</div>
<div class="field">
<%= f.label :price %><br />
<%= f.text_field :price %>
</div>
<div class="field">
<%= f.label :description %><br />
<%= f.text_area :description %>
</div>
<div class="users">
<%= f.label :users %>
<% @users.each do |user| %>
<p>
<%= check_box_tag "appointment[user_ids][]", user.id, @appointment.user.include?(user) %>
<%= user.email %> </p>
<% end %>
</div>
<div class="actions"> <%= f.submit %> </div>
<% end %>
class Appointment < ActiveRecord::Base
attr_accessible :date_time, :description, :price, :users, :user_id, :users_ids
has_many :users, :through => :users_appointments
has_many :users_appointments
end
使用我不知道你想做什麼。你可以添加你已經嘗試過的東西/你當前的表單和新的/編輯動作的代碼,以及你希望最終格式化數據的方式嗎? –