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|Last
Lessons:- Destroying Microposts

The application code is also analogous to the user case in Listing 9.48; the main difference is that, rather than using an admin_user before filter, in the case of microposts we have a correct_user before filter to check that the current user actually has a micropost with the given id. The code appears in Listing 10.49, and the result of destroying the second-most-recent post appears in Figure 10.17.

 

 

In the correct_user before filter, notethat we find microposts through the association:

current user.microposts.find by id(params [:id])

 

This automatically ensures that we find only microposts belonging to the current user. In this case, we use find_by_id instead of find because the latter raises an exception when the micropost doesn’t exist instead of returning nil. By the way, if you’re comfortable with exceptions in Ruby, you could also write the correct_user filter like this:  

 
 
 
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)