Search code examples
ruby-on-railsrubysimple-form-for

Sipmle Form For - displaying a value different from the model attribute


I have a form where I wish to perform a calculation on a date before displaying it. The model has a field for start, and a method adjusted_start and adjusted_finish which I want to display instead of the raw attribute.

I've tried:

f.input :start, as: time, label: false, minute_step: 5, value: openingtime.adjuted_start

However this is over ridden with the raw 'start' attribute. Is there any way to get it to display a different value than the one it has stored for start?

Thanks in advance.


Solution

  • I guess it should be input_html: { value: openingtime.adjuted_start }. You need to wrap html attributes in input_html hash. Check out doc.