我正在制作一个用于更新或保存已保存消息的表单。
<% 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
我确信有一种相当简单的方法可以做到这一点,但我无法理解它。