Creating an interactive div with the syntax 'link_to'

I have an interactive div, but instead of using the full address for the link, I would like to use the ruby ​​'link_to' syntax. How would I point to "facebook_path" instead of the full address?

<div id="item_1", onclick="location.href='http://www.facebook.com';" style="cursor:pointer;"> Home </div>
+4
source share
3 answers

You can do this using the following syntax:

<%= link_to "http://www.facebook.com", id:"item_1" do %>
  #your code here
<% end %>

Hope this is what you were looking for

+4
source

I assume you are just using erb, but you can pass the block to the helper link_to. So your example:

<%= link_to 'http://www.facebook.com' do %>
  <div id="item_1" style="cursor:pointer;">
    Home
  </div>
<% end %>
0
source

, css rails ( ):

a, :

<%= link_to your_path_helper, class: "class", id: "id" do %>
   Stuff here
<% end %>

HTML-:

<a href="http://your_path.com/helper" class="class", id="id">Stuff here</a>

: " , (div )". - css:

#app/assets/stylesheets.css
a.id {
   color: #000; /* makes the link color black */
   text-decoration: none; /* Removed underline */
}

CSS , . class id , css properties

, a , div. a, CSS

0

Source: https://habr.com/ru/post/1540160/


All Articles