This is a follow-up to How to I serve data from an object's associations in rails forms?
I am wondering, I would like to use eager loading to serve to an edit page of an Article object the tags (as well as other attributes that are saved through associated tables. In the previous question, I was informed that I could use eager loading of associations to pre-load that data. IE in the controller I augment the .find call to include
@article = Article.find(params[:id], :include => [:tags])
This would be great except it has two main caveats. First is that it serves the object to the field in the form. So, in this example, the :tags field in the edit form would be populated with:
[#<Tag id: 298, name: "Wondering">]
Rather than
Wondering
The second caveat is that I can't serve these associations to custom fields. For example, rather than have a :tags field I have a :tag_list field. On creation of an Article, users input a number of tags here. On edit, the :tags don't get mapped by name and put into the tag_list field. I could always add this line to the controller:
@article.tag_list = @article.tags.map(&:name)
But I'm looking for a more elegant solution, because I have very many fields for which I would have to write this, and it seems like a waste of lines of code.
Anyone can help?