[Ruby] Implementing button transition using link_to in Rails

less than 1 minute read

Overview

What I want to implement this time is an implementation that gives a link to the button like the image below with the link_to method.

syuppinn.png

By clicking this’Sell’ button, you can move to the link of the given product posting page.

There are two ways

There are two ways to implement this feature. I’m not sure why link_to is better…

  • Description with a href element

ruby:xxx.html.erb


<a href="path">
Description of the listing image or text
</a>

・Description in link_to

ruby:xxx.html.erb


<%= link_to("URL") do %>
Write the HTML code here
<% end %>

Example

The code described in this implementation is pasted as a reference example.

ruby:xxx.html.erb


<div class='purchase-btn'>
  <span class='purchase-btn-text'>Sell</span>
  <%= link_to ("/products/new") do %>
    <%= image_tag'camera.png' ,size: '185x50' ,class: "purchase-btn-icon" %>
  <% end %>

</div>

Tags: ,

Updated: