Hi
My models are message_thread, message, document (document with
attachments I am using paperclip)
message_thread
has_many messages
message
belongs_to message_thread
has_many :document_messages
has_many :documents, :through => :document_messages
document
has_attached_file :attachment,
:storage => :database
has_many :document_messages
has_many :messages, :through => :document_messages
What i need is to create a message_thread with one message and that
message with 2(or more) attachments. I tried like
messages_controller
def new
@message_thread = MessageThread.new
@message = @message_thread.messages.build
end
new.html.erb
<%form_for @message_thread, :url => { :action => “create” },:html =>
{:multipart => true,:class => “mail-tenant”} do |f| %>
<%= f.text_field :mail_to %>
<% f.fields_for :messages do |message| %>
<%= message.label :subject,‘Subject’ %>
<%= message.text_field :subject,:maxlength => 255 %>
Attachments:
<% message.fields_for :documents do |document| %>
<%= document.file_field :attachment,:class => “file” %>
<%= document.hidden_field :company_id,:value =>
current_company.try(:id)%>
<%end%>
<%end%>
Send
Or Cancel
<%end%>
But I am getting error
ActiveRecord::AssociationTypeMismatch in MessagesController#create
Document(#-614356858) expected, got Array(#-608120208)
Please help me to solve this. I have a vague idea of using
accepts_nested_attributes_for . But please tell here can I use it
Thanks in advance
Tom