HAML - how to display the value of a variable?

I have varabla var. If I try to bring it as a value in HAML = 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 there?

+5
source share
2 answers

I think you might need a method .inspect.

= val.inspect

This will show you something like:

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

Of course, if you want to dive into specifics (for example, you want to show someone an attribute url(or any other attribute that you have), then use this method:

= val.url

What will be shown:

the url
+9
source

Using Haml

%h2
  #{@project.name}

or

%h2
  #{org.id}
+14
source

All Articles