gpt4 book ai didi

javascript - 如何在使用 Paperclip 上传图像时发出通知

转载 作者:行者123 更新时间:2023-12-03 06:48:28 24 4
gpt4 key购买 nike

当使用回形针上传图像时,有什么方法可以在页面上添加诸如“成功上传”之类的通知吗?

头像上传是我的简单表单的一部分,这是当前代码:

<div class="img-circle">
<%= profile_avatar_select(@user) %>
</div>
<%= f.input :avatar, as: :file, label: "false" %>
</div>

我的application_helper.rb

def profile_avatar_select(user)  
return image_tag user.avatar.url(:medium),
id: 'image-preview',
class: 'img-responsive img-circle profile-image' if user.avatar.exists?
image_tag 'default-avatar.png', id: 'image-preview',
class: 'img-responsive img-circle profile-image'
end

在 user.rb 中:

has_attached_file :avatar, styles: { medium: '152x152#' }  
validates_attachment_content_type :avatar, content_type: /\Aimage\/.*\Z/
end

最佳答案

application.html.erb

<% flash.each do |k,v| %>
<%= content_tag :div, v, class: "alert alert-#{k} text-center" %>
<% end %>

Controller

#in a method right above render or redirect
flash[:success] = "Image Uploaded"

关于javascript - 如何在使用 Paperclip 上传图像时发出通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37613464/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com