如何使用可点击的Rails Link制作DIv? [英] How to make a DIv with a Rails Link clickable?

查看:88
本文介绍了如何使用可点击的Rails Link制作DIv?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个大div:

.limeskin:hover {
  background: #eee;
  cursor: pointer;
  display: block;
}

我想要点击。因为我正在使用Rails,我需要点击一个Rails链接:
例如

that I want to be clickable. Because I'm using Rails I need to have a Rails link be clickable: For example

<%= link_to 'Edit Your Email Address', edit_user_path %>

我正在努力解决这个问题。

I'm struggling to this.

以下是整个区块:

<% @user.posts.each do |post| %>
     <div class="lists">
      <ol class="limeposts">
       <li>
        <div class="limeskin">
          <div class="limebox">
            <div class="limecost">
              <b>Price:</b>
              <%= number_to_currency(post.price, :unit => "R") %><br>
              [...]
<% end %>

任何简单的法律可行答案?

Any simple legal workable answers?

谢谢

推荐答案

link_to 可以接受一个块:

<%= link_to root_path do %>
  <div>Hey!</div>
<% end %>

这将围绕div包含< a> 标签。

This will surround the div with <a> tags.

文档: http:// apidock .com / rails / ActionView / Helpers / UrlHelper / link_to

或者如果你有一个大的div并且想让它可点击,使用jQuery:

Or if you have a big div and want to make it "clickable", using jQuery:

# html.erb
<div class="limeskin">
  <div class="limebox">
    <div class="limecost">
      <b>Price:</b>
      <%= number_to_currency(post.price, :unit => "R") %><br>
      #[...]
    </div>
  </div>
</div>

# jQuery.js
$('.limeskin').click( function(event) {
  var clicked_div = $(this);
  # do stuff with the event object and 'this' which 
  # represent the element you just clicked on
});

这篇关于如何使用可点击的Rails Link制作DIv?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆