1

新しい Contact モデルを作成するフォームがあります。

カット&ペーストで手入力しています。

時々、左右に空白を追加してしまうことがあります。

これがcreateコントローラーの内容です(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
4

1 に答える 1

5

これが役立つかもしれません: http://scottmoonen.com/2009/05/08/rails-pattern-trim-spaces-on-input/

于 2010-11-24T23:05:40.330 に答える