简体   繁体   English

Rails:使用partials创建一个表单包装器

[英]Rails: Create a form wrapper using partials

I have a form_for in all of my views. 我所有的意见都有一个form_for。 Now I need to insert a hidden html input element in all of these views. 现在,我需要在所有这些视图中插入一个隐藏的html input元素。

Is there anyway I could specify a wrapper over form using partials where I take all the form parameters , do my own logic of inserting the hidden input element and render the rest of the block given by the views? 无论如何,我可以使用我使用所有表单参数的partials在表单上指定一个包装器吗,我自己的逻辑是插入隐藏的输入元素并呈现视图给出的其余块吗? How can I do this? 我怎样才能做到这一点?

Yes, I think you can write your own logic in views through helpers, Helpers provide you more flexibility, consistency, and also provide functionality to keep your code DRY(the basic feature of Rails). 是的,我认为您可以通过帮助器在视图中编写自己的逻辑,帮助器为您提供更大的灵活性,一致性,还提供了使代码保持DRY(Rails的基本功能)的功能。 you can write your helper methods in app/helpers/application_helper.rb. 您可以在app / helpers / application_helper.rb中编写您的帮助程序方法。 You can have a look on this guide: http://guides.rubyonrails.org/form_helpers.html 您可以查看此指南: http : //guides.rubyonrails.org/form_helpers.html

Hope it will help you in what you were looking for.Thanks 希望它能对您的需求有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM