Rails button_to 修改样式

ane · 2013年11月08日 · 最后由 u1378130755 回复于 2013年11月08日 · 2598 次阅读

在 rails 里 button_to 会生成一个表单按钮, 我的想法很简单,给提交按钮加 css

<%= button_to 'Add to Cart', line_items_path(product_id: product),form_class: "btn btn-xs btn-success"  %>
<form action="/line_items?product_id=2" class="btn btn-xs btn-success" method="post">
    <div>
         <input type="submit" value="Add to Cart" />
         <input name="authenticity_token" type="hidden" 
                   value="HMA/OoHsxcmpr01sj8f7QE7bB95e5Oa7aCuSv9OX8gU=" />
   </div>
</form>

但出来的效果不行,

其实就是 class 定位到 form 级别,对于 input 的级别是没有起作用的,如何在 button_to 中添加 class 支持 input?

不是 Form class 啊,直接使用<%= button_to 'Add to Cart', line_items_path(product_id: product),class: "btn btn-xs btn-success" %>就好

#1 楼 @chunlea 我去,原来如此简单,thanks
😚

需要 登录 后方可回复, 如果你还没有账号请 注册新账号