如何在Rails 4应用程序中向form_for帮助器添加类? [英] How to add a class to the form_for helper in a Rails 4 app?

查看:91
本文介绍了如何在Rails 4应用程序中向form_for帮助器添加类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用引导CCS设置我的Rails 4应用程序的样式,但是在使用form_for辅助程序时无法弄清楚如何向表单添加类.我没有在其他几个线程上遵循建议.两个这样的线程...

I'm using bootstrap CCS to style my Rails 4 app, but cannot figure out how to add a class to the form when using the form_for helper. I have followed the suggestions on several other threads without success. Two such threads...

  • How do you override the class name in the form_for helper?
  • adding (not overwriting a class) for a form generated by the form_for helper

该应用程序按照说明应能正常工作,但我也希望它看起来也不错.这是工作代码,并注释掉了第一行,因为它没有按我的需要向表单中添加其他类.

The app works as it should per the instructions, but I want it to look good too. Here is the working code and have commented out the first line as it does not add the additional class to the form as I need it to.

有人可以帮助解决这一挑战吗?希望今天有一些聪明的Rails开发人员可以为您提供帮助.

Can anyone help with this challenge? Hopefully there is some smart Rails developers available to help out today.

推荐答案

您可能会得到答案,尽管以下几点可能对您有所帮助

You might have got your answer,though these are some points might help you

form_for,其类名称为haml:

form_for with class name in haml:

= form_for @patient, :html => {:class => "form-horizontal"} do |f|

它也可以写为

= form_for @patient, {:html => {:class => "form-horizontal"}} do |f|

但是不能写成

- form_for @patient, :html => {:class => "form-horizontal"} do |f| #it gives error.

希望有帮助!

这篇关于如何在Rails 4应用程序中向form_for帮助器添加类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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