2010-11-24 42 views
1

我有一個表單來創建一個新的聯繫人模型。在Rails中創建新模型時,是否有一種乾淨的方式來使用strip:params?

我通過剪切和粘貼手動輸入數值。

有時我最終會在左右兩側添加空白。

這是什麼是在創建控制器(我有一個循環,檢查我是否已經上傳了一個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 

回答

相關問題