local_assigns 撈 page A 的所有參數
#page A.html.erb <%= render 'shared/B', a: 'zz', b: 'zizi' %> #page B.html.erb <%= local_assigns.fetch(:c, b) %> # 如果沒有c參數,則由b取代//= require_tree .
自動撈所有資料夾底下的檔案.env 設定
#page A.html.erb <div><%= ENV['PROJECT_NAME'] %></div> #.env PROJECT_NAME=Hello This is Zizigem devise (登入使用)
# config/initializers/devise.rb # 底下的配置,一般來說是用 :delete,但無法使用 a link 的方式登出,所以把配置改成 get config.sign_out_via = :get建立 model (db)
bin/rails generate model Article title:string text:text # app/models/article.rb and db/migrate/20140120191729_create_articles.rb (會產生這樣的檔案) bin/rails db:migrat-
# 建立所有的 action resources :photos find_by & find 區別
# 用 find_by 的話,如果搜尋不到會傳回 nil collection.find_by(id: params[:id]) # 用 find 的話,如果搜尋不到會傳回 error (500 server error) collection.find(params[:id]) # 所以一般都用 find_bysymbol and hash 區別 (String and Symbol in Ruby)
>> :name.class => Symbol >> {}.class => hash config = { :foo => 123, :bar => 456 } puts config[:foo] # 輸出 123 config["nothing"] # 是 nil
reference