简体   繁体   English

rails形式的f.input有什么作用?

[英]What does f.input in a rails form do?

I started to program with Rails after i finished some lessons in Ruby. 在我完成Ruby课程后,我开始使用Rails编程。 When i looked at someone's code I got confused. 当我看着别人的代码时,我感到困惑。 It looked like he makes some form using Rails but I just can't understand how it works. 看起来他使用Rails制作了一些表单,但我无法理解它是如何工作的。 Well just take a look on the code... Hopefully you can help me to understand this: 好吧,看看代码......希望你能帮助我理解这个:

=f.inputs do
   =f.input :type, :as => :transmission, :label => false
   =create_submit_link('Do something',:id=>'transmit')

Now the f.input row will print me 3 rows of following stuff: (row 1): radio_button | 现在f.input行将打印出3行以下内容:(第1行):radio_button | labeltext | labeltext | text_field; 文本域; (row 2): 1x radio_button |labeltext| (第2行):1x radio_button | labeltext | number_field; number_field; (row 3): radio_button |labeltext| (第3行):radio_button | labeltext |

How is that possible? 怎么可能? :O :o

f.inputs is not defined in rails. f.inputs未在rails中定义。 You may be using "simple-form" gem. 你可能正在使用“简单形式”的宝石。 Simple Form has various views helpers to generates html contents. Simple Form有各种视图助手来生成html内容。 It has various method such as: text , radio , email however :as => :transmission options seems to be user defined as its not defined in "simple form" also. 它有各种方法,例如: textradioemail但是:as => :transmission选项似乎是用户定义的,因为它也没有以“简单形式”定义。 You can take look at https://github.com/plataformatec/simple_form/blob/master/lib/simple_form/action_view_extensions/form_helper.rb . 您可以查看https://github.com/plataformatec/simple_form/blob/master/lib/simple_form/action_view_extensions/form_helper.rb f.input work same as f.textbox or similar to rails but it has much more options than bare rails html helpers. f.input工作一样f.textbox或类似的轨道,但它比裸轨HTML辅助更多的选择。

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

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