开发者

Rails: find_by, conserving leading whitespaces

when I do the following

def somefunction
      @texts = A.find_all_by_someid(someid)
      respond开发者_如何学Python_to do |format|
        format.xml  { render :xml => @texts }
      end
end

it gets the string from the db correctly, except if the string has leading whitespaces, it seems they are trimmed. Note: the whitespaces are there in the db correctly

What can I do to conserve those whitespaces? Thanks


for me it's working.

@texts = User.find_all_by_system_role(2)
@texts.length #gives me 13
@texts[2]     #gives me
<User id: 2, username: "  salil@hh.com", 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
"  salil@hh.com"

Which is correct.

We need some more code like how you retrive value form the object.


What are you looking at when you decide that the whitespace is missing? Are you trying to view XML in a web browser, because that would probably not behave as you intend. Open your data in a text editor and see what's actually there.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜