gpt4 book ai didi

ruby-on-rails - 在多部分simple_form中更新回形针头像

转载 作者:行者123 更新时间:2023-12-03 23:22:11 25 4
gpt4 key购买 nike

我想为以下表单创建一个编辑页面。问题在于,当用户浏览到编辑页面时,brand_name和name被预先填充,但是即使“ style”的化身存在,图像上传字段也显示“ no selected selected”。请让我知道是否有某种方法可以解决此问题。谢谢!

我的编辑表单:

<%= simple_form_for @style, :html => { :class => 'form-horizontal' }, :remote => true do |m| %>

<%= m.input :brand_name, :label => 'Brand', :placeholder => 'Brand' %>
<%= m.input :name, :label => 'Style', :placeholder => 'Style' %>
<%= m.input :avatar, :label => "Image" %>

<div class="form-actions" style = "background:none">
<%= m.submit nil, :class => 'btn btn-primary' %>
<%= link_to 'Cancel', styles_path, :class => 'btn' %>
</div>

<% end %>

最佳答案

昨天才实施。在/ app / inputs中进行自定义输入

class AvatarInput < SimpleForm::Inputs::FileInput
def input
out = '' # the output string we're going to build
# check if there's an uploaded file (eg: edit mode or form not saved)
if object.send("#{attribute_name}?")
# append preview image to output
# <%= image_tag @user.avatar.url(:thumb), :class => 'thumbnail', id: 'avatar' %>
out << template.image_tag(object.send(attribute_name).url(:thumb), :class => 'thumbnail', id: 'avatar')
end
# append file input. it will work accordingly with your simple_form wrappers
(out << @builder.file_field(attribute_name, input_html_options)).html_safe
end
end


那你可以做

<%= f.input :avatar, :as => :avatar %>

关于ruby-on-rails - 在多部分simple_form中更新回形针头像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10266005/

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