Ruby On Rails Classroom image

Anil  Bist / Professional / Web Technology

 
To post your Question Join Classroom
 
Lesson Topics's No:-  First|1 | 2 | 3 | 4 | 5 | 6 | 7|Last
Lessons:- A Proto-feed

This example shows just how flexible the RSpec boolean convention is; even though include is already a Ruby keyword (used to include a module, as seen in, e.g., Listing 8.14), in this context RSpec correctly guesses that we want to test array inclusion.

       We can arrange for an appropriate micropost feed method by selecting all the microposts with user_id equal to the current user’s id, which we accomplish using the where method on the Micropost model, as shown in Listing 10.39.10

 

 

Micropost .where ( "user id = ?" id )

 

ensures that id is properly escaped before being included in the underlying SQL query, thereby avoiding a serious security hole called SQL injection. The id attribute here is just an integer, so there is no danger in this case, but always escaping variables injected into SQL statements is good habit to cultivate.            

             Alert readers might note at this point that the code in Listing 10.39 is essentially equivalent to writing    def  feed  def feed

def feed
       microposts
end

 

We’ve used the code in Listing 10.39 instead because it generalizes much more naturally to the full status feed needed in Chapter 11.

        To test the display of the status feed, we first create a couple of microposts and then verify that a list element (li) appears on the page for each one (Listing 10.40).

 
 
 
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)