On step 5, what is the significance of image_tag
? The exercise passes without it if you were type only <%= t.image %>
Hi Jay,
t.image
is the image’s URL. So,
<%= t.image %>
will show in Codecademy’s virtual browser as something like:
https://s3.amazonaws.com/codecademy/codecademy-content/...
Whereas this:
<%= image_tag t.image %>
will show up as:
(or whatever image is hosted at t.image
)
I hope this helps!
Thanks for the explanation Zeke. I’m still not fully grasping this.
To clarify, is the url for the image stored in the seeds.rb file from the db? I’m assuming yes. Also, is the image_tag equivalent to HTML’s version of alt=“image description” ?
@jaydacoder That’s fine, no worries
is the url for the image stored in the seeds.rb file from the db?
Not quite. The image URL is stored in the database, seeds.rb
simply fills the database with data when you run rake db:seed
.
Also, is the image_tag equivalent to HTML’s version of alt=“image description” ?
No, <%= image_tag %>
compiles to:
<img src="[t.image's value]" alt="optional parameter you can pass in to image_tag">
Feel free to ask any followup questions you may have
Many Thanks Z! Appreciate your help. I think I understand now. To clarify…
-
image_tag is a helper so that RoR automatically knows to look in the assets folder for that image without having to type the entire path. ie) /assets/images/photo.jpg ???
-
If the image URL is stored in the db, is it stored in the file in the migrate folder? For example, 20150408005247_create_destinations.rb ?
You’re getting closer, but still don’t quite understand it completely.
-
image_tag
: You can use it to get images stored inassets/
, or you can use it to get an image at any location, for example one hosted on Imgur instead or something,image_tag
isn’t limited to images stored in theassets
folder. - The file in the
migrate
folder simply tells the database what data and types of data to store. You can’t see the actual database anywhere, it’s hidden.
You’re starting to get it, let me know if you have any more questions