1

I've been trying for a while now to auto fill a string from my database onto action text, without luck.

<%= f.rich_text_area :application,
                     placeholder: 'Hvis du har ansøgt skriftligt, så kan du ligge din ansøgning ind her',
                     value: @application %>

Does anyone know how to do this since value don't work?

demir
  • 4,591
  • 2
  • 22
  • 30
Kaspervh
  • 23
  • 3

1 Answers1

0

rich_text_area has no value parameter. So you can't set value with rich_text_area. Maybe rich_text_area_tag can solve the problem. You need to set the name. Try to set the name by adding the model name (if there is) to attribute name like this: your_model_name[application]. For example, if you created the form like form_with(@foo, ..) it should be foo[application]. You need to specify the correct name.

<%= rich_text_area_tag "your_model_name[application]",
                     placeholder: 'Hvis du har ansøgt skriftligt, så kan du ligge din ansøgning ind her',
                     value: @application %>

If @application has html tags and the content does not appear correctly, try @application.html_safe.

demir
  • 4,591
  • 2
  • 22
  • 30
  • it kinda works but now i cannot save to db... is there no way to inject text into actionText? – Kaspervh Oct 21 '19 at 12:54
  • @Kaspervh It's injecting to actionText but not saving to db? You need to set name correctly. Can you share the form method? – demir Oct 21 '19 at 13:10
  • @Kaspervh If you created the form like form_with(@foo, ..), try `<%= rich_text_area_tag "foo[application]", placeholde.. %>` – demir Oct 21 '19 at 13:25