rails interview question -


I have met this question in the previous interview and can not do this, any thoughts? What is this refund? Where can this be used?

  module application halper df show_flash flash.map {| Key, value | Content_tag (: div, value, {: class = & gt; key}}} and end  

The 'Flash' Ruby-on-Rail Conference (temporarily, "Invalid user name" or "session not found" or "Thank you for buying us") to store the information that arises for a request. Or "cart update")

Flash is an object like a hash.

.map on an object like hash is iterative over all objects in the hash; In, . The method is being passed to a block that accepts two parameters (whose name is key and value , because key hash can be used to view value ) with the new & lt; value from the hash and CSS selector-class key in the block. Div> uses content_tag assistant to output elements.

For such a flash: {: name = & gt; ; "Sir" ,: Food = & gt; "Pizza"}

It almost exceeds HTML in this way: & lt; Div class = "name" & gt; Sir & lt; / Div & gt; & Lt; Div class = "food" & gt; Pizza and lieutenant; / Div & gt; . . This is a smart helper method which probably presents a fair bit of typing, but it makes some assumptions: Order does not make any difference in the sequence, all the keys are already in the CSS or the CSS is unknown class elements. Ready to handle in a beautiful way. This assistant can be used only once in a template, but can still be useful in the form of a method which can later be dropped in other projects.


Comments