向 f.submit 添加一个类但保留默认功能? [英] Add a class to f.submit but keep default functionality?

查看:34
本文介绍了向 f.submit 添加一个类但保留默认功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

很简单的问题,我有:

<%= f.submit %>

我想对它应用 class='btn'.我知道我可以轻松做到这一点:

I want to apply class='btn' to it. I know that I can easily do this:

<%= f.submit 'Button Name', :class => 'btw' %>

但是...我如何实现同样的事情,即在不为按钮指定静态名称的情况下应用一个类?

But...how do I achieve the same thing, i.e. apply a class without specifying a static name for the button?

换句话说,鉴于我在我的表单部分中执行此操作,我希望按钮的名称根据被调用的操作(即新建、创建、更新等)而改变.那么我如何才能两全其美呢?

In other words, given that I am doing this in my form partial, I want the name of the button to change according to the action being called (i.e. new, create, update, etc.). So how do I get the best of both worlds?

推荐答案

<%= f.submit nil, :class => 'btw' %>

甚至

<%= f.submit :class => 'btw' %>

这篇关于向 f.submit 添加一个类但保留默认功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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