Bryan Zamora
Bryan Zamora

Reputation: 131

How do I use remotipart with paperclip to upload image and show in real time

This is my code

remoti.coffe

$(document).on "change", "#post_image", (en)->
$(this).submit()

_form.haml from post

    = form_for @post, remote:true do |f|
  - if @post.errors.any?
    #error_explanation
      %h2= "#{pluralize(@post.errors.count, "error")} prohibited this post from being saved:"
      %ul
        - @post.errors.full_messages.each do |msg|
          %li= msg
  .input-field
    = f.file_field :image
  .input-field
    = f.text_area :body, class: "materialize-textarea", rows: "1"
    = f.label :body, "Comparte con la comunidad"

  .actions
    = f.submit 'Publicar', class: "btn waves-effect waves-light deep-orange accent-2 right"

respond as JS

show.js.coffee

$("#posts").prepend("<%= j render 'post', post: @post%>")

render _post.haml

  .card
  .card-content
    .text-left#image_view
      = post.user.email
      =image_tag post.image(:medium)

Please help me Sorry for my english

Upvotes: 1

Views: 124

Answers (0)

Related Questions