如何将 link_to 包裹在一些 html ruby​​ 代码中? [英] How do I wrap link_to around some html ruby code?

查看:36
本文介绍了如何将 link_to 包裹在一些 html ruby​​ 代码中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在视图代码周围环绕链接?我不知道如何将带有 ruby​​ 代码的多行传递给单个 link_to 方法.我正在寻找的结果是您单击该列并获得显示页面:

<div class="c25l"><div class="subcl"><%= image_tag 相册.photo.media.url(:thumb), :class =>图像"救援 nil %>

<div class="c75r"><div class="subcr"><p><%=专辑.created_at%></p><%=link_to h(album.title),专辑%><p><%=专辑.created_at%></p><p><%=专辑.photo_count%></p>

解决方案

link_to 接受一段代码(>= Rails 2.2),它将用作标签的主体.

所以,你这样做

<%= link_to(@album) do %>html-code-here<%结束%>

但是我很确定在 a 标签内嵌套一个 div 是无效的 HTML.

根据 Amin Ariana 下面的评论添加了 = 字符.

How do I wrap a link around view code? I can't figure out how to pass multiple lines with ruby code to a single link_to method. The result I am looking for is that you click the column and get the show page:

<div class="subcolumns">
  <div class="c25l">
        <div class="subcl">
        <%= image_tag album.photo.media.url(:thumb), :class => "image" rescue nil  %>
        </div>
    </div>
  <div class="c75r">
        <div class="subcr">
            <p><%= album.created_at %></p>
            <%= link_to h(album.title), album %>
            <p><%= album.created_at %></p>
            <p><%= album.photo_count %></p>
        </div>
  </div>
</div>

解决方案

link_to takes a block of code ( >= Rails 2.2) which it will use as the body of the tag.

So, you do

<%= link_to(@album) do %>
  html-code-here
<% end %>

But I'm quite sure that to nest a div inside a a tag is not valid HTML.

EDIT: Added = character per Amin Ariana's comment below.

这篇关于如何将 link_to 包裹在一些 html ruby​​ 代码中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
其他开发最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆