I collect tags in a nice javascript UI widget. It then takes all the tags and passes them to the server as tag1,tag2,tag3,etc in one text_field input. The server receives them:
params[:event][:tags] = params[:event][:tags].split(',') # convert to array
@event = Event.find(params[:id])
Is there a better way to convert the string to the array? It seems like a code smell. I have to put this both in update and in the new actions of the controller.
you could do this in the model:
I have seldom experience on mongoid. The following would work in active record (the only difference is the write_attribute part)
On the other hand, for consistency, you may want to do the following:
In the first case (directly overwriting the
tags=method),tags=accepts a string buttagsreturns an array.In the second case,
tags_for_form=andtags_for_formaccepts and returns string, whiletags=andtagsaccepts and returns array.