Ruby On Rails Classroom image

Anil  Bist / Professional / Web Technology

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

User/Micropost Associations

When constructing data models for web applications, it is essential to be able to make associations between individual models. In the present case, each micropost is associated with one user, and each user is associated with (potentially) many microposts—a relationship seen briefly in Section 2.3.3 and shown schematically in Figure 10.2 and Figure 10.3. As part of implementing these associations, we’ll write tests for the Micropost model that, unlike Listing 10.2, are compatible with the use of attr_accessible in Listing 10.7.

 

 

 

Using the belongs_to/has_many association defined in this section, Rails constructs the methods shown in Table 10.1.

      Note from Table 10.1 that instead of

Micropost . create
Micropost . create!
Micropost . new

 

we have

user.microposts.create
user.microposts.create!
user.microposts.build 

 

 

 
 
 
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)