Attenzione ad usare unscoped per inibire il default_scope
Scritto da Silvio Relli circa un anno fa. Jan3
Su un'applicazione Rails 3, mettiamo ci sia un default_scope sul modello Article che restituisce soltanto gli articoli pubblicati.
Con la seguente interrogazione
@article = current_user.articles.unscoped.find(params[:id])
vorremmo ottenere un determinato articolo anche se non è pubblicato, usando il metodo unscoped per annullare l'effetto del default scope.
Purtroppo però unscoped annulla anche il controllo sulla relazione dell'articolo con l'utente, togliendo praticamente il where che filtra l'utente dalla select, e permettendo di ottenere il post di un utente qualsiasi.
Similmente con @articles = current_user.articles.unscoped.all non otteniamo solamente gli articoli del current_user ma bensì tutti gli articoli.
Non solo si tratta di un comportamento inaspettato e non documentato, ma anche non auspicabile.
Fate molta attenzione perchè l'uso di unscoped può portare a comportamenti decisamente indesiderabili!

A versatile and ultra striking pair of Ray Ban Uk sunglasses for women, the Ray Ban Wayfarer are highly reminiscent of a cat-eye style but with a more subtle shape, allowing you to channel the iconic look but in a more understated fashion. The sunglasses feature a thick acetate frame that becomes thicker at the outer vertical edges and draws to a point at the upper outer corners creating a suggestion of the cat-eye flick. The arms become narrower towards the ear stems and display the signature Ray-Ban logo in raised metal lettering positioned adjacent to the hinge. The overall aesthetic detailing remains minimal accentuating the versatility of the sunglasses. The Ray Ban Aviators are available in neutral and flattering colours including a shiny havana and tortoiseshell patterned frame with crystal green lenses and a shiny black frame with crystal green lenses. Some styles are also available with polarised lenses for the ultimate in visual quality and protection.