Ruby On Rails Classroom image

Neeraj  Amoli / Professional / Web Technology

 
To post your Question Join Classroom
 
Lesson Topics's No:-  First|1 | 2 | 3 | 4|
Lessons:- Micropost Refinements

 

Here we have used Micropost.find_by_id, which returns nil if the record is not found, whereas Micropost.find raises an exception on failure, which is a bit harder to test for. (In case you’re curious,

 

does the trick in this case.)

The application code to get Listing 10.15 to pass is less than one line; in fact, it’s just an option to the has_many association method, as shown in Listing 10.16.

 

Here the option dependent::destroy in

has many :microposts, dependent: :destroy

 

arranges for the dependent microposts (i.e., the ones belonging to the given user) to be destroyed when the user itself is destroyed. This prevents userless microposts from being stranded in the database when admins choose to remove users from the system.

        With that, the final form of the user/micropost association is in place, and all the tests should be passing:  

$ bundle exec rspec spec/
 
 
 
image
Neeraj  Amoli

Skills    Ruby On Rails

Qualifications :-
Location :-Dehradun,Dehradun,Uttrakhand,India
Description:-

I have 3 year experience as a Software Engineer. My Skilled are Android Development (Java), ROR Development .   


Explore
 

  Students (0)