Genadinik
Genadinik

Reputation: 18649

HAML - how to display the value of a variable?

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?

Upvotes: 6

Views: 22527

Answers (2)

Dru
Dru

Reputation: 9820

Using Haml

%h2
  #{@project.name}

or

%h2
  #{org.id}

Upvotes: 14

MrDanA
MrDanA

Reputation: 11647

I think you may want the .inspect method.

= val.inspect

That will show you something like:

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

Of course, if you want to dive in to specifics (for example, you only want to show someone the url attribute (or whatever attribute you may have), then use that method:

= val.url

Which will show:

the url

Upvotes: 11

Related Questions