我在製作更新或保存保存的消息的表單。form_for中的rails參數
<% form_for @draft, :url => {:controller => "drafts", :action => "draft_actions"} do |f|%>
subject
<%=f.text_field :subject %>
recipients
<%=f.text_field :draft_recipients %>
<br /> <%= f.text_area :body %>
<%= submit_tag "save", :name => "resave_draft"%>
<%= submit_tag "send", :name => "send_draft" %>
<% end %>
,但我想顯示在一個不錯的方式收件人,用逗號分隔:中user1, user2, user3
代替user1user2user3
我的問題是:我不明白如何讓在:recipients
符號映射到我的收件人屬性我的模型草案,但仍然有顯示的收件人視圖中顯示我多麼希望
的代碼爲我draft
模型
class Draft < ActiveRecord::Base
belongs_to :message
belongs_to :draft_recipient, :class_name => "User"
delegate :created_at, :subject, :user, :body, :draft_recipients, :to => :message
我的消息模型的代碼如下
class Message < ActiveRecord::Base
belongs_to :user
has_many :recipients, :through => :message_copies
has_many :draft_recipients, :through => :drafts
has_many :message_copies
has_many :drafts, :class_name => "Draft", :foreign_key => :message_id
attr_accessor :to #array of people to send to
attr_accessible :subject, :body, :to, :recipients, :author, :user
我敢肯定有一個相當簡單的方式來做到這一點,但我不能讓我的頭周圍。
你可以把草稿模型的代碼? –
'收件人'在哪裏?如果'draft_recipients'替代它,它是如何在'Message'模型中定義的? –
對不起,它確實是draft_recipients。 – Arthur