- Read Tutorial
- Watch Guide Video
Now that we have the ability to upload images and have them render in the application. In this lesson, we are going to learn how to make images clickable.
There are many ways to do, and we'll see one such way to get it done.
The easiest is probably to embed it within a <a>
tag in html like this:
<a href = "<%= post_url(post) %>"></a>
In this code, post_url
is the route. If you're unsure, run rake routes
in the console to identify the right url for this action. In this case, this is the show
route. We're passing the post object to this method.
We are passing a URL here because that's what the <a href= ""></a>
tag is expecting, and it may throw an error if we pass the object directly.
Let's start the server, and check this in the browser. If you see, each image is clickable and the code works!