简体   繁体   中英

Rails: Create a form wrapper using partials

I have a form_for in all of my views. Now I need to insert a hidden html input element in all of these views.

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? 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). you can write your helper methods in app/helpers/application_helper.rb. You can have a look on this guide: http://guides.rubyonrails.org/form_helpers.html

Hope it will help you in what you were looking for.Thanks

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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