Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the principle and function of gem

2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article introduces in detail "what is the principle and function of gem" for everyone. The content is detailed, the steps are clear, and the details are properly handled. I hope this article "what is the principle and function of gem" can help you solve your doubts. Let's go deeper and learn new knowledge together with the ideas of the editor.

This gem is mainly used to realize the following similar to Twitter, and the listening function of Sina is mainly the association of two models. For example, if a user subscribes to a book, we can realize User.first.follow(Book.first) like this.

It is implemented by using two polymorphisms, one called follower and the other called follower. The class name string and id of each object are stored in the database to realize association. The other code realizes the query code about the two. The following is the relationship between the two.

12has_many :followings, :as => :followable, :dependent => :destroy, :class_name => 'Follow'has_many :follows, :as => :follower, :dependent => :destroyfollow.rb12belongs_to :followable, :polymorphic => truebelongs_to :follower, :polymorphic => true Read here, this article "gem principle and role is what" article has been introduced, want to master the knowledge of this article also need to do your own practice to understand, if you want to know more about the content of the article, welcome to pay attention to the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report