0

別のテーブルからフィールドを追加したいと思います。テーブルは結合テーブルとモデルと一致しています。ビュー インデックスは分割でき、完全に機能します。

<%= @something.map(&:name).join(", ") %>

"new"/"edit"フィールドを何に入るかに追加する方法を誰かがアドバイスでき"form"ますか?

テキストフィールドまたは「ユーザー」の完全な詳細(名前、住所など)が必要です。コード入力の提案に感謝します。

これはコードが使用したものです:model:user、予定、view/_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
4

2 に答える 2