Rails Simpleform with non-model inputs

前端 未结 3 1210
北海茫月
北海茫月 2020-12-15 20:35

I have a normal form using simpleform. Now I\'d like to add an input that does not have any corresponding field in the model, it will be processed by the controller. I tried

3条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-15 21:17

    Why don't you add:

    attr_accessor :attr
    

    to your model's class definition? This way your code:

    <%= f.input :attr %>
    

    should work.

    OR

    If this solution isn't suitable, you can always pass some value to your input method directly:

    <%= f.input :attr, input_html: {value: 'something'}  %>
    

提交回复
热议问题