180401

railsbook - Rack 應用程式

什麼是 Proc 物件?

180327

Rails console 的用法:

  • [x] Debug 畫面下的 console: (解決 bug 後如何再開啟?)

  • 透過 Gemfile 內,開發模式群組內的 gem web-console 得到這個功能:

  • 可以寫在 view 的 html.erb 內,做出一個 console 視窗
    <%= console if Rails.env.development? %>

180320

  • [ ] 嘗試在 railsbook/shopping_mall 專案 的購物車頁面新增“編輯”和“刪除”商品的功能。
    • [x] 完成刪除功能:
    • [ ] 編輯數量功能:

180120

180118

在進行29章的 bundle install 時,遇到 puma 套件的安裝失敗問題:

Fetching puma 3.6.2
Installing puma 3.6.2 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

解決方法:https://stackoverflow.com/questions/30143180/puma-gem-failed-to-build-gem-native-extension

gem install puma -v '3.6.0' -- --with-opt-dir=/usr/local/opt/openssl

180109

What does :: do?

:: is a scope resolution operator, it effectively means "in the namespace", so

ActiveRecord::Basemeans "Base, in the namespace ofActiveRecord"

::Constant means a Constant not in any namespace at all.(最上層)

module Document
  class Table # Represents a data table

    def setup
      Table # Refers to the Document::Table class
      ::Table # Refers to the furniture class
    end

  end
end

class Table # Represents furniture
end

see: https://stackoverflow.com/questions/4829189/what-does-do/4829239#4829239

180103

  • [ ] expect(cart.empty?).to be false To figure out what is .to be

180102

  • [ ] 為什麼在hello_rails 專案的 BMI 計算機首頁重新整理,會出現 Routing Error ? No route matches [POST] "/bmi"

  • [ ] railsbook p.370 購物車為何選擇使用 Session 取代資料庫存放資料?

  • [ ] Session 是什麼?

  • PORO = Plain Old Ruby Object

171229

  • [ ] 讀取專案後,放在專案資料夾中任何位址的 .rb 檔案(例如models/@@@module.rb or app/services/@@@class.rb)都可以引入嗎?

  • [x] module/class 定義釐清

  • class = 類別,類似烤蛋糕的模具,烤出來的蛋糕= 實體 Instance, 會用到 @實體變數 (活在實體內),外部要取用的話必須配合 attr_reader, attr_writer, attr_accessor 方法

    • class Cat < Animal:貓咪類別繼承動物類別
    • model算是一個class
  • module = 模組,相當於外掛功能,使用 module ConstantName 常數名稱來定義,在類別裡面include ModuleName來掛上模組。

    • 模組無法 new 一個實體出來,且無法繼承其他模組

171228

  • There are more ClassMethod 'Callback' in Controller that we could use to organize the code logic in View, check out api.rubyonrails.org.

171227

  • RSpec : One kind of frame to test our app.

    • Install: gem install rspec

    • Test result:

      • "." = pass

      • "F" = failure

      • "*" = pending

  • 如果想要用輕量化的工具架設網站,可以考慮採用 Sinatra 或 Hanami

171226

  • [ ] How to test if the gem "delayed_job" working properly?

171220

  • [ ] In Rails Book p.313, how we storage account/password in different place?
  • [ ] What is Environment(production, development, test) means in Rails?
  • [x] Can't sent email - 171226 problem solved after I reboot the rails server!

171219

解決自訂驗證器問題:

  1. 把驗證器 class 整個移到程式碼前面就成功了。

  2. 另外做一個驗證器 "begin_with...validator.rb"放在 models 資料夾

171217

  1. When to use a nested class, or just separate to different base class?
class User < ApplicationRecord
  has_one :store
  # 171217 練習加入自訂驗證器
  validate :name_validator

  private
  def name_validator
    unless name.start_with? 'Ruby'
      errors[:name] << "必須是 Ruby 開頭喔!"
    end
  end

end
  1. 自訂驗證器失敗 #171219 解決

Tried to follow the method that could create our own validator which shown in p.303 :

  class BeginWithRubyValidator < ActiveModel::EachValidator
    def validate_each(record, attribute, value)
      unless value.starts_with? 'Ruby'
        record.errors[attribute] << "必須是 Ruby 開頭。"
      end
    end
  end
# 171217 Shall/Can we nest this class into User class?

171213

實現了名詞複數型轉換功能 rails 框架內的正則表達式的替換規則沒有看懂:

https://github.com/rails/rails/blob/master/activesupport/lib/active_support/inflections.rb#L11

Rails Book (為你自己學ROR):

  • General
    • 將需要的 Gem 寫進 Gemfile 並存檔後,記得執行一次 bundle install

p.222 Author change this line:

  @candidate.increment(:vote)

to this:

  @candidate.creat(ip_address: request.remote_ip) if @candidate

What is the difference between these two line above?

  • FormBuilder (read about it)
  • simple_form 使用失敗: ould not find generator 'simple_form:install'. Maybe you meant 'system_test', 'integration_test' or 'scaffold'

  • Routes:

    shallow: true p.165

  • Http Verb (how to trigger?)

  • Model:

    p.219 How it works? How to connect other Model and method? => # 171205 在 generate migration 時採用的一些特殊命名慣例

results matching ""

    No results matching ""