rails 3:将链接显示为按钮? [英] rails 3: display link as button?
问题描述
在一些非表单页面上,我有一些链接看起来更像是按钮而不是超链接......
On some non-form pages, I have a few links that would look better as a button than a hyperlink...
我认为 button_to 而不是 link_to 会起作用,但 buton_to 似乎总是被视为帖子.
I thought button_to instead of link_to would work, but buton_to seems to always be treated as a post.
是否有一种简单的方法可以简单地用按钮替换(非提交)链接?
Is there an easy way to simply replace a (non-submit) link with a button?
推荐答案
你所要做的就是添加一个 :method =>get"
到 button_to 的末尾,使其被视为链接
All you have to do is add a :method => "get"
to the end of your button_to to get it to be treated like a link
使用users_path
<%= button_to "BUTTON: link version", users_path, :method => "get" %>
CSS 方式
或者,您可以使用更简洁的(从网页设计的角度来看)方法,而不是实际将表单插入到您的 html 中(这就是 button_to 实际所做的),并且实际上只是以某种方式设置链接的样式,使其看起来像按钮这有几个好处
这是一篇关于如何这样做,这是该代码的一小段,实际上只取决于使用边框,填充和背景图像
Here is a great article on how to do it and here is a little snippet of that code, really just depends on playing around with the border, padding and background image
a.button {
background: transparent url('bg_button_a.gif') no-repeat scroll top right;
color: #444;
display: block;
float: left;
font: normal 12px arial, sans-serif;
height: 24px;
margin-right: 6px;
padding-right: 18px; /* sliding doors padding */
text-decoration: none;
}
代码来自上面的链接.无论您选择哪种方法都应该可以正常工作,尽情享受吧!
The code comes from the link above. Whichever method you choose should work fine, enjoy!
这篇关于rails 3:将链接显示为按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!