[問題] 相同的instance和class method
如果有相同結構的instance和class method,要如何做才能dry呢?
class Product < ActiveRecord::Base
def price
...
end
def self.price
...
end
end
class ProductsController < ApplicationController
# use in ajax call
def calculate
price = Product.price
end
end
謝謝各位大大
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 118.100.110.131
討論串 (同標題文章)
以下文章回應了本文:
完整討論串 (本文為第 1 之 4 篇):
Ruby 近期熱門文章
PTT數位生活區 即時熱門文章