轨道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?
推荐答案
所有你需要做的就是添加一个:方法=> 搞定
您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实际上做),你可以用清洁剂(从网页设计的角度来看)方法去,实际上只是风格的方式链接,使它看起来像一个按键
这样做有几个好处
这里是如何做到这一点这里是code的小片段,真的只是取决于与边框,填充和背景图像
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;
}
在code来自上面的链接。无论您选择哪种方法,都应该正常工作,享受!
The code comes from the link above. Whichever method you choose should work fine, enjoy!
这篇关于轨道3:显示链接的按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!