简体   繁体   中英

Upload and render image in nested form RoR

I have two models 1)Posts, 2)Photos and they are associated as follows Posts has many Photos and Photos belongs to Posts. I am using ryanbates nested form gem to generate the form. The Form is setup something like this

<%= nested_form_for @post, :html => {:multipart => true} do |f| %>
    <%= f.fields_for :photos do |p| %>
        <%= p.file_field :image %>
    <% end %>
<% end %>

What I am trying to do is have one page with this form and have the field for the photo upload and display the image inline. I have seen ryans screencast "jquery upload" but I don't want the user to change between screens. I understand that this is pretty complex because photos is dependent on post, should I consolidate the two tables, or do you know of any gem that supports this? Also I am using carrierwave but if I have to switch I will. Thanks

If you want to upload image and display it inline without changing between screens, i think you have to do it through ajax. For your requirement, i think it would be better to use individual forms, rather than nested form.

Nested forms are used to submit both posts and photos together. If you want to submit photos individually and display inline, you can use separate form for photos,posts and submit them with ajax. I think, Carrierwave is enough to fill your requirement.

Hope it helps!!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM