我已经使用继承控制器代码。Rails控制器 - 继承自定义动作
class MastersController < ApplicationController
def index
...
...
end
...
...
end
class ItemsController < MastersController
end
现在我已经加入了自定义操作的MastersController
class MastersController < ApplicationController
def index
...
...
end
...
...
def clone
...
...
end
end
我已经添加了项目
resources :items do
get :clone
end
现在的路线,当我尝试访问myapp.dev/items/ 1 /克隆,我得到错误
AbstractController::ActionNotFound at /items/1/clone
The action 'clone' could not be found for ItemsController
如果我在ItemsController中添加'clone'操作,错误消失。
class ItemsController < MastersController
def clone
...
...
end
end
我如何抽象Rails中控制器的自定义操作?
另一个问题是围绕同一主题http://stackoverflow.com/questions/22604996/rails-controller-inheritance-vs -concerns-and-mixins –
这是一个答案吗? http://stackoverflow.com/questions/3998286/inheriting-and-routing-a-custom-action-from-applicationcontroller-in-rails(tadman的回答) –
是'克隆'低于任何私人方法?尝试在'def clone'上面添加单词'public'一行' – gabrielhilal