mercredi 25 février 2015

form_for losing nested attributes when moved to different location

Overall Goal: be able to post status from button in header without leaving current page.


I placed my form_for into a modal with a button in the header. After a few edits I've gotten it to post from any page but only with the comments and not the attachments, as the attachments (nested attribute through :documents) doesn't even appear. After changing form_for line to



<%= simple_form_for(Status.new, as: @status, :url => {:action => :create}) do |f| %>


I was able to see attachment input if I'm already on the New Status page but nowhere else.


I'm assuming it's an controller issue?


Entire form in modal:



<!-- Modal -->
<div class="modal storyModal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title" id="myModalLabel">Post story</h4>
</div>
<div class="modal-body">
<%= simple_form_for(Status.new, as: @status, :url => {:action => :create}) do |f| %>

<%= f.input :content, input_html: { rows: 6, class: 'input-xxlarge' } %>
<%= f.fields_for :document, as: :status do |document_fields| %>
<%= document_fields.input :attachment, as: :file %>
<% end %>
</div>
<div class="modal-footer">
<%= f.button :submit, "Post Story", class: 'btn btn-success' %>
<% end %>
</div>
</div>
</div>
</div>

Aucun commentaire:

Enregistrer un commentaire