Ruby On Rails Classroom image

Anil  Bist / Professional / Web Technology

 
To post your Question Join Classroom
 
Lesson Topics's No:-  |1 | 2 | 3 | 4|Last
Lessons:- Followed users

  Followed users

We come now to the heart of the Relationship associations: followed_users and followers. We start with followed_users, as shown Listing 11.9.

 

The implementation uses has_many through for the first time: A user has many following through relationships, as illustrated in Figure 11.7. By default, in a has_many through association Rails looks for a foreign key corresponding to the singular version of the association; in other words, code like

has many :followeds, through: :relationships

 

would assemble an array using the followed_id in the relationships table. But, as noted in Section 11.1.1, user.followeds is rather awkward; far more natural is to use ‘‘followed users’’ as a plural of ‘‘followed,’’ and write instead user.followed_users for the array of followed users. Naturally, Rails allows us to override the default, in this case using the :source parameter (Listing 11.10), which explicitly tells Rails that the source of the followed_users array is the set of followed ids.

 

 
 
 
image
Anil  Bist

Skills    Ruby On Rails

Qualifications :- High School - SLV, College/University - Graphic Era Deemed Univ University,
Location :-Dehradun,Dehradun,Uttarakhand,India
Description:-

I started my Professional Journey in 2006 with one of the Web Development Company in Bangalore and my 1st framework was "Ruby on Rail" as Web development and delivered around 5+ Projects using this platform. Then came another dimension as JEE/Sturst framework, Gradually I realized that I want to build something on my own and give my passion and energy on creating something different a
Explore

 

  Students (0)