هل هناك طريقة جافة لاستخدام الشريط على الكل: params عند إنشاء نموذج جديد في القضبان؟

StackOverflow https://stackoverflow.com/questions/4272028

  •  28-09-2019
  •  | 
  •  

سؤال

لدي نموذج لإنشاء نموذج اتصال جديد.

أدخل القيم باليد عن طريق القطع واللصق.

في بعض الأحيان ينتهي بي الأمر إلى إضافة مساحة بيضاء على اليسار واليمين.

إليكم ما هو موجود في وحدة التحكم في إنشاء (لدي حلقة تتحقق إذا كنت قد قمت بتحميل VCard والتي ، من الواضح أنها لا تقدم المشكلة عادة (على الرغم من أنها يمكن أن) - لكن مشكلتي الكبيرة هي عندما أكتبها بنفسي.

 def create

    @contact = Contact.create(params[:contact])

     unless @contact.vcard.path.blank?

           paperclip_vcard = File.new(@contact.vcard.path) 

       @vcard = Vpim::Vcard.decode(paperclip_vcard).first
       @contact.title = @vcard.title
       @contact.email = @vcard.email
       @contact.first_name = @vcard.name.given
       @contact.last_name = @vcard.name.family
       @contact.phone = @vcard.telephone
       @contact.address.street1 = @vcard.address.street
       @contact.address.city = @vcard.address.locality
       @contact.address.state = @vcard.address.region
       @contact.address.zip = @vcard.address.postalcode
       @contact.company_name = @vcard.org.fetch(0)

    end

    @contact.user_id = current_user.id # makes sure every new user is assigned an ID    
    if @contact.save
      #check if need to update company with contact info
      @contact.update_company

      @contact.new_todos #create the todos for the newly created contact

      flash[:notice] = "Successfully created contact."
      redirect_to @contact
    else
      render :action => 'new'
    end
  end
هل كانت مفيدة؟
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top