# Attaching multiple files at a time on a has\_many through

**URL:** <https://www.ruby-forum.com/t/attaching-multiple-files-at-a-time-on-a-has-many-through/193030>\
**Category:** Rails\
**Created:** [August 10, 2010, 8:43am UTC](https://www.ruby-forum.com/t/attaching-multiple-files-at-a-time-on-a-has-many-through/193030 "2010-08-10T08:43:03Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![tom-mac](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/bc8723/32.png) [@tom-mac](https://www.ruby-forum.com/u/tom-mac)\
**Post date:** [August 10, 2010, 8:43am UTC](https://www.ruby-forum.com/t/attaching-multiple-files-at-a-time-on-a-has-many-through/193030/1 "2010-08-10T08:43:03Z")

</div>

Hi  
My models are

class MessageThread \< ActiveRecord::Base  
has\_many :messages  
accepts\_nested\_attributes\_for :messages  
end

class Message \< ActiveRecord::Base  
has\_many :message\_participants  
belongs\_to :message\_thread  
has\_many :document\_messages  
has\_many :documents, :through =\> :document\_messages  
accepts\_nested\_attributes\_for :documents  
end

class Document \< ActiveRecord::Base  
has\_attached\_file :attachment,  
:storage =\> :database  
default\_scope select\_without\_file\_columns\_for(:attachment)  
has\_many :document\_messages  
has\_many :messages, :through =\> :document\_messages  
end

class DocumentMessage \< ActiveRecord::Base  
belongs\_to :message  
belongs\_to :document  
end

```
I have to make an email compose interface. So my messages controller

```

new and create(sample) action like

def new  
@message\_thread = MessageThread.new  
@message = @message\_thread.messages.build  
end

def create  
MessageThread.create(params[:message\_thread])  
end

```
And the new form I tried like

```

\<%form\_for @message\_thread, :url =\> { :action =\> “create” },:html =\>  
{:multipart =\> true} do |f| %\>

\<%= text\_area\_tag ‘mail\_to’,nil,:cols =\> 10, :rows =\> 3,:style =\>  
“height:30px;”%\>

  

\<% f.fields\_for :messages\_attributes do |message| %\>  
\<%= message.label :subject,‘Subject’ %\>  
\<%= message.text\_field :subject,:maxlength =\> 255 %\>  
\<%#=end %\>

  

  

**Attachments:**

  
\<%message.fields\_for :documents do |a| %\>  
\<%=a.file\_field “attachment[]”%\>  
\<%=a.file\_field “attachment[]”%\>  
\<%end%\>  

  

  
Send  

  

Or Cancel

  
\<%end%\>

And I am getting error

NoMethodError in MessagesController#create

undefined method `with\_indifferent\_access’ for “”:String

Please help me to correct this

Thanks in advance  
Tom
