Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 394
Genadinik Avatar asked Jun 22 '12 13:06

Genadinik


2 Answers

Using Haml

%h2
  #{@project.name}

or

%h2
  #{org.id}
like image 179
Dru Avatar answered Sep 29 '22 11:09

Dru


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
like image 20
MrDanA Avatar answered Sep 29 '22 13:09

MrDanA