2010-05-29 60 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