5

I have a variabla var. If I try to output its value in HAML like =val then I just get the string value of the object which looks like this: #<ShortenedUrl:0x118c50fa.

But how do I get the value that is in there?

4

2 に答える 2

14

Hamlを使用する

%h2
  #{@project.name}

また

%h2
  #{org.id}
于 2012-06-22T13:50:32.330 に答える
10

私はあなたがその方法を望むかもしれないと思います.inspect

= val.inspect

それはあなたに次のようなものを表示します:

#<ShortenedURL @url="the url", @count=0, @etc="etc">

もちろん、詳細に飛び込みたい場合(たとえば、誰かにurl属性(またはあなたが持っている可能性のある属性)だけを表示したい場合は、その方法を使用します。

= val.url

表示されます:

the url
于 2012-06-22T13:50:30.037 に答える