belongs_to的对ActiveRecord的渲染为找不到 [英] belongs_to on activerecord rendering as not found

查看:95
本文介绍了belongs_to的对ActiveRecord的渲染为找不到的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须做一些愚蠢的事在这里。我使用Rails 3.2.19与activeadmin 0.6.0。基本上我试图通过通过侧边栏一个belongs_to的关联做了一个向下导航。我已经装我的数据库与文字固定装置,可以通过协会在铁轨控制台,即向下钻取:

I must be doing something stupid here. I am using rails 3.2.19 with activeadmin 0.6.0. Basically I'm trying to do a navigate down through a belongs_to association via a side bar. I have loaded my database with text fixtures and can drill down through the association at the rails console, i.e:

2.1.1 :004 > Employee.first.blogposts.first
Employee Load (0.1ms)  SELECT "employees".* FROM "employees" LIMIT 1
Blogpost Load (0.1ms)  SELECT "blogposts".* FROM "blogposts" WHERE "blogposts"."employee_id" = 615722309 LIMIT 1
=> #<Blogpost id: 298486374, title: "Mine too", body: "Can we try markdown?", employee_id: 615722309, created_at: "2014-07-25 03:27:14", updated_at: "2014-07-25 03:27:14"> 
2.1.1 :005 > 

我的模型协会是没有任何幻想。基本上是简单的,因为他们可以:

My model associations are nothing fancy. Basically as simple as they can be:

class Blogpost < ActiveRecord::Base
  belongs_to :employee
end

class Employee < ActiveRecord::Base
   has_many :blogposts
end

和同我的主动管理资源。我建立这些基础上的文档。

And the same with my active admin resources. I built these based on the documentation.

ActiveAdmin.register Employee do

  sidebar "Details", only: [:show, :edit] do
    ul do
      li link_to("Blogposts", admin_employee_blogposts_path(employee))
    end
  end
end

ActiveAdmin.register Blogpost do
  belongs_to :employee
end

我还可以看到路由指定,当我做耙路线

I can also see the route specified when I do rake routes

admin_employee_blogposts GET        /admin/employees/:employee_id/blogposts(.:format)              admin/blogposts#index

员工页(在员工资源定义的)上的链接呈现没有错误,但是当我点击它,我得到:

The link on the employee page (the one defined at the Employee resource) renders without error, however when I click on it I receive:

NoMethodError在管理:: BlogpostsController#指数 未定义的方法'发现'的零:NilClass 参数: {雇员标识=>615722309}

NoMethodError in Admin::BlogpostsController#index undefined method `find' for nil:NilClass Parameters: {"employee_id"=>"615722309"}

在浏览器中指定的网址是:

The URL specified in the browser is:

http://localhost:3000/admin/employees/615722309/blogposts

有谁知道如何解决呢?我相信,在有关的特定员工ID有博客文章,因为我证明通过使用轨道控制台。任何帮助任何人都可以提供将大大AP preciated。

Does anybody know how to troubleshoot this? I am certain that the particular employee ID in question has blog posts, as I demonstrated by using the rails console. Any help anybody could provide would be greatly appreciated.

感谢您,

丹·沙利文

推荐答案

请尝试使用这样的:

ActiveAdmin.register Blogpost do
  belongs_to :employee, parent_class: Employee
end

这篇关于belongs_to的对ActiveRecord的渲染为找不到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆