0
這就提出了一個錯誤「未定義的方法喜」:如何Rails是處理繼承的概念,家長訪問子女
class A
def bla
hi
end
end
class B < A
def hi
puts "Hii"
end
end
a = A.new
a.bla
我有一個Rails應用程序,這是否:
class BlaParentController < ApplicationController
before_filter :setting
def create
@random_obj = ParentRandom.create(permitted_params)
end
end
class BlaController < BlaParentController
private
def setting
end
def permitted_params
end
end
一個方法調用BlaController#create
轉到BlaParentController#create
。但BlaParentController
正在從其子BlaController
訪問方法permitted_params
和setting
。這怎麼可能?
你的第二個例子沒有意義。什麼是「ParentRandom」?如果你有直觀的類作爲例子,它也會更容易。 '動物','狗','GermanShepherd',這是清楚如何繼承的作品。 – Amadan
對不起,它必須是這種方式......但你可以使用子類的方法'允許的參數和設置'來獲得父類的想法 – gates