ruby on rails - Problem building relationships between models -
So far, I am using the act_as_taggable_on plugin for tagging announcements.
This plugin creates the following tables:
Tagging: related to the table of tags and declarations (for tag items, there is a field labeled tagGable_ID, which I call "declanation_id" I change the name I explain below).
Tags: Tag IDs and names are.
On the second day, I came to know that I have a certain tag, but Announcement.tagged_with (tag_name)
is doing, and I do not want to search by name, but for ID.
So, because of the functionality of that plugin I'm not using almost anything, I decided to make a model for tagguns and tag tables to complete it: Announcement.tags
.
The relationships of the models are displayed in the following form:
edit:
class tagging & lt; ActiveRecord :: Base is_to: Announcement ist_to: tag end class tag & lt; ActiveRecord :: Base has has_many: tagging has_many: Announcements, via = & gt; : Tagging & Class Announcement & lt; ActiveRecord :: Base has has_many: Tagging has_many: tags, via = & gt; : Tagging
Why can not I run the command Announcement.tags
?
You have actually posted that you have tried Announcement.ags
. But there will be a method on tag
an announcement
, and it is calling it as a method on the announcement
class, which will not work
Assuming that you are actually calling an_announce.tags
, you must announcement
and tag
Code> tagging - is similar:
class declaration & lt; ActiveRecord :: Base has has_many: Tagging has_many: tags, via = & gt; Tagging end class tag & lt; ActiveRecord :: Base has has_many: tagging has_many: Announcements, via = & gt; : Tagging end
Comments
Post a Comment