Hello everyone.
I’ve recently finished the RoR tutorial and decided to try to build an example blog application.
I’m trying to implement functionality that allows:
- A link that will just list all articles in a nice way.
- A link that will list all tags and the articles that they reference
I’m having trouble with 2) though. Everything I need for an Article is easy enough to generate with scaffolding but I’m having trouble figuring out how to implement tags.
My thought process around this was to have a Tags text box on the form. I would scan that string, extract the tags (space-seperated) sequences of characters that match the pattern [a-zA-Z0-9]. Then build the association between that article and a tag when needed.
My Article model has a has_many :tags association. The db migration for tags has a foreign_key referencing an article_id. I think that this is enough.
I’m getting weird behavior on the front-end though with the form. Specifically, the forms tag text box is being auto populated with a: #Tag::ActiveRecord_Associations_CollectionProxy:0x00007f4931244308
The error occurs with the strong parameters for the article. I think that this might be caused by the symbol name for tags colliding in certain aspects, the Article model has a tags attribute which is a text field, the forms label and text_area references the same symbol, i.e. :tags. I’m not too familiar with Ruby but I know symbols should be unique, so it’s probably suspect to have two “meanings” of :tags as i’ve listed.
Does anyone have any advice for me? Am I misunderstanding something pretty major here? Any help would be appreciated.