2018年3月9日 星期五

[Ruby]路徑,不使用helper的情況下 & 實戰聖經 Action View Helpers介紹、處理圖檔

執行rails s 後,會導向預設歡迎畫面,並非我們預期的 index,
要去 config/routes 編輯加入
  root "(table_name)s#index"

(rails建立app的第一步,參考: https://ihower.tw/rails/firststep.html)

導回首頁使用 <a>而非helper (方便的 link_to root_path),
要設定 href="/"或"/(table_name)s",值設成 ""或 "#"的話只會刷新後停留在當前頁面。
例:
  table_name = product
  首頁導為 localhost:3000/products
  設定為 href="/"或"/products"。
  若設定為 href="products"
  在其他頁面點擊後會變成導向 localhost:3000/products/products

已在 controller設定好 action,不使用link to helper 要前往第n筆資料的情況:
  href="/products/<%= product.id %>"
  注意!".id"不可省略!

(參考: 在Rails中使用Path或是Url的時機)

Ruby on Rails 實戰聖經 Action View - Helpers 方法
Ruby on Rails 實戰聖經 如何處理 image 圖檔

沒有留言:

張貼留言