如何在嵌套资源路由下加载hasmany关系的记录



我认为辅助路径将加载所有logs,即belongs_to父记录remote_focu

tool_cvt_remote_focu_remote_focu_logs_path(tool_cvt_remote_focu)

但它没有,它仍然加载remote_focu_log的所有记录。

怎么了?

路线

  namespace :tool do
    namespace :cvt do
      resources :remote_focus do
        resources :remote_focu_logs
      end
    end
  end

日志控制器中的索引操作

  def index
    @tool_cvt_remote_focu_logs = Tool::Cvt::RemoteFocuLog.all
  end

如果我想保留直接访问的正常路由,我应该在route.rb 中添加重复的类似路由规则吗

  namespace :tool do
    namespace :cvt do
      resources :remote_focu_logs
    end
  end

改为:

def index
  @tool_cvt_remote_focu_logs = Tool::Cvt::RemoteFocuLog.all
end

应该是这样的:

def index
  @tool_cvt_remote_focu_logs = Tool::Cvt::RemoteFocu.find(params[:remote_focu_id]).remote_focu_logs
end

scaffold只为每个资源生成一些通用的基本函数

最新更新