假设同一视图中有两个表单,我想知道如何在表单之间设置输入标签。 像这样。
= form_for @restaurant, url: {action: restaurant_path} do |r|
= r.fields_for :restaurant_translations do |rt|
dl.field
dt = rt.label (t :restaurantname)
dd = rt.text_field :restaurantname, autofocus: true, size: 120
dl.field
dt = rt.label (t :restauranttel)
dd = rt.text_field :restauranttel, autofocus: true, size: 120
dl.field
dt = rt.label (t :restaurantaddr)
dd = rt.text_field :restaurantaddr, autofocus: true, size: 120
dl.field
dt = r.label (t :url)
dd = r.text_field :url
dl.field
dt = r.label (t :storehours)
dd = r.text_field :storehours
目前,订单是这样的。
如果可能,我想像这样设置表单顺序。
目前,混合不同的表单标签太难了。 有谁知道怎么样?请告诉我。
答案 0 :(得分:0)
您需要使用多个fields_for
表单助手
= form_for @restaurant, url: {action: restaurant_path} do |r|
dl.field
dt = r.label (t :url)
dd = r.text_field :url
= r.fields_for :restaurant_translations, @restaurant_translation do |rt|
dl.field
dt = rt.label (t :restaurantname)
dd = rt.text_field :restaurantname, autofocus: true, size: 120
dl.field
dt = r.label (t :storehours)
dd = r.text_field :storehours
= r.fields_for :restaurant_translations, @restaurant_translation do |rt|
dl.field
dt = rt.label (t :restauranttel)
dd = rt.text_field :restauranttel, autofocus: true, size: 120
dl.field
dt = rt.label (t :restaurantaddr)
dd = rt.text_field :restaurantaddr, autofocus: true, size: 120
来自控制器操作构建@restaurant_translation
@restaurant_translation = @restaurant.restaurant_translations.build
我希望这会对你有所帮助