2010-05-29 59 views
1

當我做以下的Rails:find_by,節約領先的空格

def somefunction 
     @texts = A.find_all_by_someid(someid) 
     respond_to do |format| 
     format.xml { render :xml => @texts } 
     end 
end 

它從數據庫中獲取正確的字符串,但如果字符串領先的空格,看來他們被修剪。 注意:db中的空格是否正確

我該如何保護這些空格? 謝謝

回答

0

對我來說它的工作。

@texts = User.find_all_by_system_role(2) 
@texts.length #gives me 13 
@texts[2]  #gives me 
<User id: 2, username: " [email protected]", password: "aab7130a678e8ec95287169a4e7baac80e162a9f", system_role: 2, user_type: 1, activation_code: nil, activation_status: "active", coupon_id: nil, created_at: "2010-04-28 16:16:58", updated_at: "2010-05-27 15:44:39", flag: nil, temporary_password: nil> 

and 
@texts[2].username #gives me 
" [email protected]" 

這是正確的。

我們需要一些更多的代碼,比如如何回收價值形成對象。

0

當你決定缺少空白時,你在看什麼?您是否試圖在Web瀏覽器中查看XML,因爲這可能不像您打算的那樣工作。在文本編輯器中打開數據並查看實際存在的內容。

+0

對不起,回來這麼晚,但薩利爾是正確的,它的工作。我發現它在其他地方搞亂了。在執行respond_to/render xml之後,空白區被剝離了一段時間,並且它從Flex函數中檢索。不完全確定在哪裏。 – peppermonkey 2010-06-09 21:21:14