ruby on rails - display array in text_field with semicolon delimeters -
i have ruby on rails form displays values of array stored in mongodb document.
in _form.html.erb file: <%=f.text_field :tags%>
. displays tags array in text field separated spaces.
example in tags array have: ["recon","scanning","network"]. in text field on web page displayed "recon scanning network". i want display on web page "recon; scannnig; network" because have method in model split input semicolon:
def tags=(values) values = values.split(";") write_attribute(:tags, values.reject(&:blank?)) end
with being displayed spaces, doesn't save database properly. it'll save array ["recon scanning network"] instead :\
so question is, how can arrays display in text_field
seperated semicolons?
try
<%= f.text_field :tags, value: f.object.tags.join('; ') %>
btw, converntion in ruby write variables , methods names in underscore notation.
Comments
Post a Comment