Inserting Images

  • Images are defined with the <img> tag.
  • Image tags are "empty," meaning they have no closing tag and no element content.

For example:

<img src="url" />

The URL points to the location where the image is stored. For example, if the image baby.jpg was stored in the images folder at the root of the site the URL would read images/baby.jpg.

Images in Rails

Rails has a helper method to assist you in inserting images into your application as well.

  • Images are stored in the public/images directory of your site.
  • The public folder houses information that is directly available to the browser, such Style Sheets, Javascript, and Images.

How to insert an image using Ruby on Rails:

<%= image_tag("baby.jpg") %>

The above code will display baby.jpg from your images folder in your browser.

Also available in: HTML TXT