Rails 管理插件问题,针对同一模型的多对多关系

发布于 2024-10-11 21:41:47 字数 1316 浏览 2 评论 0原文

我一直在关注这篇文章中的第二个解决方案: Rails 中同一模型的多对多关系?

使用插件 Rails Admin (https: //github.com/sferik/rails_admin

使用下面的代码,似乎特别破坏了 Rails Admin:

class PostConnection < ActiveRecord::Base
  belongs_to :post_a, :class_name => :Post
  belongs_to :post_b, :class_name => :Post
end

我能做什么有什么想法吗?

更新:

这是请求的错误:

NoMethodError in Rails_admin/main#index

Showing /Users/elliot/.rvm/gems/ruby-1.8.7-p299/bundler/gems/rails_admin-5713b1671e8c/app/views/rails_admin/main/index.html.erb where line #18 raised:

undefined method `match' for :Post:Symbol
Extracted source (around line #18):

15:           <tbody>
16:             <% @abstract_models.each do |abstract_model| %>
17:               <tr class="<%= cycle 'odd', 'even' %>">
18:                 <td class="modelNameRow">
19:                   <%= link_to(RailsAdmin.config(abstract_model).list.label, rails_admin_list_path(:model_name => abstract_model.to_param), :class => "show") %>
20:                 </td>
21:                 <td>

I've been following the 2nd solutions on this post: Many-to-many relationship with the same model in rails?

While using the plugin Rails Admin ( https://github.com/sferik/rails_admin )

Using the code below, specifically seems to be breaking Rails Admin:

class PostConnection < ActiveRecord::Base
  belongs_to :post_a, :class_name => :Post
  belongs_to :post_b, :class_name => :Post
end

Any ideas for what I can do?

Update:

Here is the error as requested:

NoMethodError in Rails_admin/main#index

Showing /Users/elliot/.rvm/gems/ruby-1.8.7-p299/bundler/gems/rails_admin-5713b1671e8c/app/views/rails_admin/main/index.html.erb where line #18 raised:

undefined method `match' for :Post:Symbol
Extracted source (around line #18):

15:           <tbody>
16:             <% @abstract_models.each do |abstract_model| %>
17:               <tr class="<%= cycle 'odd', 'even' %>">
18:                 <td class="modelNameRow">
19:                   <%= link_to(RailsAdmin.config(abstract_model).list.label, rails_admin_list_path(:model_name => abstract_model.to_param), :class => "show") %>
20:                 </td>
21:                 <td>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

淡淡の花香 2024-10-18 21:41:47

在模型的belongs_to语句中,尝试更改 :class_name =>; :Post:class_name => 'Post'(字符串与符号)。我很确定这就是错误消息的相关内容。

In your model's belongs_to statements, try changing :class_name => :Post to :class_name => 'Post' (string vs symbol). I'm pretty sure that's what the error message is related to.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文