升級 rails 後,執行 rspec。跳出了這個錯誤
NameError:
uninitialized constant ActionDispatch::Assertions::SelectorAssertions
原因:
ActionDispatch::Assertions::SelectorAssertions 在 4.2 版移至 ::Rails::Dom::Testing::Assertions::SelectorAssertions
Ref:
-fix for Rails
»
bundle update rails responders
兩個要一起更新,不然會發生錯誤
Bundler could not find compatible versions for gem "actionpack":
In Gemfile:
rails (~> 4.1.14) was resolved to 4.1.15, which depends on
actionpack (= 4.1.15)
responders (= 2.4.0) was resolved
»
css 裡的 width、height(寬/高) 計算方法
是 padding(外邊框) + margin(內邊框) + border(邊框) + width/height(寬/高)本身
example
範例中 a 與 b width 都是 500px,margin 20px
b 多了 padding 20px 與 border-width 10px
b 就比 a 長了很多
解法參考 [CSS] box-sizing
Ref:
Introduction to the CSS
»
解決 padding、margin 影響寬度造成破版的問題
box-sizing: content-box;
元素實際寬高,為 CSS 指定寬高,再加上 border/padding/margin
box-sizing: border-box;
元素實際寬高,即為 CSS 所指定寬高 (已包含 border/padding/margin)
example
Ref:
CSS3 box-sizing 屬性
»
可以透過 base64 的方式,將圖片轉成文字編碼,降低網頁連線請求數量
但編碼過後的 base64 檔案大小會增大
使用時機:
使用 base64 時,若發現圖片轉換成文字後是好幾 MB,或者是網站上都是圖片,那就還是保持原先的連線即可,或者是透過 Lazyload 延遲圖片載入
base64 比較適合將一些小圖片轉成文字,例如: 社群分享小圖、Icon …等等,其他內容圖片或是 banner 圖片,比較不建議這樣做轉換
線上轉 base64 網站:
Base64 Image
DATAURL
»
一種程式設計技巧,可以減少 nesting,並增加可讀性
提早 return,如果條件不符合。後面就不會繼續執行
example:
function(err, result) {
if (err) {
handleError(err)
} else {
doSomething()
doMore()
// ... etc
}
}
// 簡化成
function(err, result) {
if (err) {
handleError(
»