Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

General Discussion

Setting an Image size with .erb syntax?

In a twitter bootstrap app I am trying to set the size of an image in my navbar. I am using .erb syntax. This is my current syntax:

  <%= image_tag 'ctclogonew.png', alt: 'logo' %>

I haven't been able to find a command such as size: or height: to adjust the size of the image like I could do using html.

Does anyone know if this is possible?

Furthermore, a guide I was following in a different project instructed me to make pages with a .erb tag. For instance, my home page is home.html.erb. If I changed this to home.html and take out any erb syntax and change it to html, will this work in my ruby on rails/boot strap app? Or do I have to use ERB syntax for all my html pages?

Thanks :)

3 Answers

<%= image_tag 'ctclogonew.png', alt: 'logo', style:"height: ??; width: ??;" %>

This works, its better to use a class over inline styles though. And inline styles are better than the HTML equivilants.

Thanks, worked perfect. Where/how would I insert a class with erb?

The image_tag function looks like this:

def image_tag(src, options = {})

Everything after the first arguement is a hash, which in ruby 1.9.3 or above you can use like a splat arguement. You used to have to do:

image_tag 'test.png', {alt: 'this is an alt'}or image_tag 'test.png', {:alt => 'this is an alt'} depending on your ruby version, now you can just do:

image_tag 'test.png', alt: 'this is an alt', class: 'apply this class', other_options: 'infinite number of options to be added to the hash'

which would be the same as:

image_tag 'test.png', {alt: 'this is an alt', class: 'apply this class', other_options: 'infinite number of options to be added to the hash'}

Thanks Richard! Great info!