我想从另一个表中添加一个字段。这些表已与连接表和模型匹配。可以支付视图索引并且它工作得很好。
<%= @something.map(&:name).join(", ") %>
有人可以建议如何将字段添加到"new"/"edit"
进入的内容中"form"
吗?
需要一个文本字段或“用户”的完整详细信息,例如姓名、地址等。非常感谢您对代码输入的建议。
这是使用的代码:模型:用户,约会,视图/_form_for约会。我正在尝试将用户和患者添加到约会表中,但这似乎很复杂。
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