From 52278963c618cbd98fcec39d81067cbf3d9888bd Mon Sep 17 00:00:00 2001 From: Ender Ahmet Yurt Date: Wed, 12 Jun 2013 01:41:50 +0300 Subject: [PATCH] Goon --- episodes/415 - Upgrading to Rails 4/tr.html | 54 +++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/episodes/415 - Upgrading to Rails 4/tr.html b/episodes/415 - Upgrading to Rails 4/tr.html index 5e511f0..bba8c8e 100644 --- a/episodes/415 - Upgrading to Rails 4/tr.html +++ b/episodes/415 - Upgrading to Rails 4/tr.html @@ -97,5 +97,59 @@ # match 'new', to: 'episodes#new', via: [:get, :post] get 'new', to: 'episodes#new' ``` +

Spec'lerimizi çalıştırmayı denediğimiz zaman nedeni mass-assigning protected attributes olan bir çok hata ile karşılaşıyoruz. Bu hatalar Papertrail'ın Version modelinden geliyor. Bu durum Rails 4'de strong paramaters ile çalıştırılmalı fakat biz hala protected attributes kullanıyoruz. Uygulamamızın config dosyasını modifiye ederek başlayabiliriz. active_record.whitelist_attributes özelliğini false olarak ayarlıyoruz. Bu özellik başlangıçta true olarak geliyor ve bunu anlamı ise her model içinde attr_accessible'ın beklenmesidir.

+ +``` /config/application.rb +config.active_record.whitelist_attributes = false +``` + +

Bütün spec'lerimiz artık başarı ile geçiyor. Ancak buna rağmen hala uyarı mesajları alıyoruz. Bir kaçından kurtulmayı deneyelim. Bunların bir kısmı whiny_nils gibi artık desteklenmiyecek özelliklerin olduğu config dosyaları içinden geliyor. Development config dosyası içindeki whiny_nils alanı kaldırıp, yerine eager_load özelliğini ekliyoruz ve false olarak ayarlıyoruz. Daha fazla desteklenmeyecek diğer özellikleri de dosyadan kaldırabiliriz.

+ +``` /config/development.rb +Screencaster::Application.configure do + # Settings specified here will take precedence over those in config/application.rb + + # In the development environment your application's code is reloaded on + # every request. This slows down response time but is perfect for development + # since you don't have to restart the web server when you make code changes. + config.cache_classes = false + + config.eager_load = false + + # Show full error reports and disable caching + config.consider_all_requests_local = true + config.action_controller.perform_caching = false + + # Don't care if the mailer can't send + config.action_mailer.raise_delivery_errors = false + + # Print deprecation notices to the Rails logger + config.active_support.deprecation = :log + + # Expands the lines which load the assets + config.assets.debug = true +end +``` +

Production modunu düzenleyeceğiz. Öncelikle bunu config.assets.compress ekliyoruz.

+ +``` /config/production.rb +config.eager_load = true + + # Compress JavaScripts and CSS + config.assets.js_compressor = :uglifier +``` +

Test ortamında ise whiny_nils'i kaldırmalı ve yerine eager'ı ekleyip false olarak ayarlamalıyız. mass_assignment_sanitizer'ı da strong paramters kullandığımız için kaldırmalıyız.

+ +``` /config/test.rb +# Log error messages when you accidentally call methods on nil +# config.whiny_nils = true +config.eager_load = false + +# Raise exception on mass assignment protection for Active Record models +# config.active_record.mass_assignment_sanitizer = :strict +``` + + +