Ruby On Rails Classroom image

Anil  Bist / Professional / Web Technology

 
To post your Question Join Classroom
 
Lesson Topics's No:-  |1 | 2 | 3|Last
Lessons:- User/Relationship Associations

 User/Relationship Associations

Before implementing followed users and followers, we first need to establish the association between users and relationships. A user has_many relationships, and—since relationships involve two users—a relationship belongs_to both a follower and a followed user.

         As with microposts in Section 10.1.3, we will create new relationships using the user association, with code such as

user.relationships.build ( followed id: ...)

 

We start with some tests, shown in Listing 11.2, which make a relationship variable, checks that it is valid, and ensures that the follower_id isn’t accessible. (If the test for accessible attributes doesn’t fail, be sure that your application.rb has been updated in accordance with Listing 10.6.)  

 

Note that, unlike the tests for the User and Micropost models, which use @user and @micropost, respectively, Listing 11.2 uses let in preference to an instance variable. The differences rarely matter,4 but I consider let to be cleaner than using an instance variable. We originally used instance variables both because instance variables are important to introduce early and because let is a little more advanced.

      We should also test the User model for a relationships attribute, as shown in Listing 11.3.

 
 
 
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)