加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – 更改模型的输入名称

发布时间:2020-12-16 22:01:19 所属栏目:百科 来源:网络整理
导读:使用ActiveAttr: class Filter include ActiveAttr::Model attribute term # Overriding to_key,to_param,model_name,param_key etc doesn't help :(endclass SpecialFilter Filterend 如何覆盖ActiveModel以生成所有子类的(相同)预定义输入名称? = form_f
使用ActiveAttr:
class Filter
  include ActiveAttr::Model
  attribute term
  # Overriding to_key,to_param,model_name,param_key etc doesn't help :(
end

class SpecialFilter < Filter
end

如何覆盖ActiveModel以生成所有子类的(相同)预定义输入名称?

= form_for SpecialFilter.new,url: 'xx' do |f|
  = f.text_field :term

因此,而不是< input name ='special_filter [term]'/>我需要得到< input name ='filter [term]'/>

注意:场景更复杂(使用simple_form和radio / checkboxes / dropdown等),因此请不要建议更改类的名称或类似的解决方法.我确实需要使用表单生成器使用的一致名称.

解决方法

试试这个 :
= form_for SpecialFilter.new,as: 'filter',url: 'xx' do |f|
  = f.text_field :term

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读