2012-04-22 12 views
12

में पेपरक्लिप अवतार अपडेट करना मैं नीचे दिए गए फॉर्म के लिए एक संपादन पृष्ठ बनाना चाहता हूं। समस्या यह है कि जब उपयोगकर्ता संपादन पृष्ठ पर ब्राउज़ करता है तो ब्रांड_नाम और नाम पूर्व-भरे हुए होते हैं, लेकिन छवि अपलोड फ़ील्ड 'शैली' के लिए मौजूद होने पर भी 'कोई फ़ाइल चुनी नहीं' दिखाती है। अगर इसका समाधान करने का कोई तरीका है तो कृपया मुझे बताएं। धन्यवाद!मल्टीपार्ट simple_form

मेरे संपादित करें प्रपत्र:

<%= 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 %> 

उत्तर

18

बस कल इसे लागू किया गया।/अनुप्रयोग में एक कस्टम इनपुट बनाओ/आदानों

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 %> 
+0

क्या मुझे मणि को फोर्क करने और simple_form/lib/simple_form/inputs में जोड़ने की आवश्यकता है? – Abram

+0

पता लगाया गया है कि इसे मेरे ऐप में डालें ... इनपुट के अंदर ... बढ़िया काम। – Abram

+0

हाँ! मुझे खुशी है कि यह काम किया। क्या मुझे बक्षीस मिलती है? :) – DVG

0

paperclip's github page से नए विचारों/संपादन के लिए कोड इस तरह दिखता है:

<%= form_for :user, @user, :url => user_path, :html => { :multipart => true } do |form| %> 
    <%= form.file_field :avatar %> 
<% end %> 

तो हो सकता है आप m.file_field रूप में अच्छी तरह का प्रयास करना चाहिए और शामिल :html => { :multipart => true }? हालांकि मैं व्यक्तिगत रूप से Attachment-Fu पसंद करता हूं।

+0

इस बारे में है simple_form रेल मानक मानक –

6

यह सब मैं इस (haml में) काम करने के लिए के लिए आवश्यक है:

=simple_form_for @user, :html => {:multipart => true } do |f| 
    =f.file_field :image 
संबंधित मुद्दे