看板 Ruby 關於我們 聯絡資訊
※ 引述《little78926 (果果)》之銘言: : 大大好 : 小弟是新手上路,靠著零零散散的資訊現在正在建立我的第一個APP, : 很多術語還在學習,如果描述不夠清楚,請多見諒並提點!感謝 : 我現在面臨的兩個問題分別是 : 1.如何顯示相對應的資料 : 2.倒數計時 : --- : 問題: 如何顯示相對應的資料 : 目的: 在產品show時會同時標註創建者名稱 : 已經有: : 我現在有兩個 tables, 一個是我的產品資料庫(product)&使用者資料庫(user) : 使用者必須登入才能create,同時寫入時會輸入使用者的id(欄位user_id), : (可以知道作者是誰) : 需解決: : 我需要在個別 show 時把已寫入的user_id對應到使用者資料庫(id),並顯示出 : 創建者名稱。 : 需要透過 product.user_id 尋找對應到 user.id 並顯示 user.name 在Product model 裡面define belongs_to :user 在controller 裡find 的時候 includes(:user) 在View裡 使用 @product.user.name : --- : 問題: 倒數計時 : 目的: 顯示距離截止日剩餘的天數 : 已經有: : create時會有 開始日 和 截止日 的輸入選項 : 需解決: : 在產品呈現的時候截止日改成 : 剩餘天數,而不是直接呈現日期。 如果截止日是end_at 的話 在View 裡使用 distance_of_time_in_words(Time.now,@product.end_at) http://apidock.com/rails/ActionView/Helpers/DateHelper/distance_of_time_in_words -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 118.164.129.12 ※ 文章網址: https://www.ptt.cc/bbs/Ruby/M.1440052871.A.2C1.html
little78926: 感謝John大大~ 08/21 00:43
little78926: 新增 return "passed".blue if from_time > to_time 08/21 05:07
little78926: 可以讓過期顯示成 "passed" 感謝大大 08/21 05:07
little78926: 我想請問要如何對不同的剩餘時間輸出不同顏色? 08/21 05:08
little78926: 請忽略 .blue 不好意思 08/21 05:08
airson: 推 John 大大精闢教學 08/29 12:59
little78926: 我用if解決了 感謝 09/04 09:05