新手问题 rails 中继承过来的 controller 中的有些 action 需要屏蔽,怎么做?

kikyous · 2012年07月22日 · 最后由 help5305fff 回复于 2012年07月23日 · 2840 次阅读

效果应该就像没有那个 anction 一样

route 里面不设置不就好了

继承是is a的关系,也就是说,可以把子类完全当作一个父类来对待,所以子类必然要响应所有父类的action,否则违背继承的逻辑。所以,你可能哪里错了。programing ruby 中的一段话:

Now, a lot of research has been done on type theories. One of the more famous results is
the Liskov Substitution Principle. Formally, this states: “Let q(x) be a property provable
about objects x of type T. Then q(y) should be true for objects y of type S where S is a
subtype of T.” What this means is that you should be able to substitute an object of a child
class wherever you use an object of the parent class—the child should honor the parent’s
contract. There’s another way of looking at this: we should be able to say that the child
object is a kind of the parent. We’re used to saying this in English: a car is a vehicle, a cat
is an animal, and so on. This means that a cat should, at the very least, be capable of doing
everything we say that an animal can do.

#2 楼 @benzhang route 是 resource 的那种

我不会继承一个有 action 的类,继承的时候只会继承一些 Base controller,里面定义了一些 filter 和 private 方法。

匿名 #7 2012年07月23日

或者,你重写它,哇嘎嘎

需要 登录 后方可回复, 如果你还没有账号请 注册新账号