Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 活动管理,带有嵌套属性的formtastic,未定义的方法'call';零级:零级_Ruby On Rails_Activeadmin_Formtastic - Fatal编程技术网

Ruby on rails 活动管理,带有嵌套属性的formtastic,未定义的方法'call';零级:零级

Ruby on rails 活动管理,带有嵌套属性的formtastic,未定义的方法'call';零级:零级,ruby-on-rails,activeadmin,formtastic,Ruby On Rails,Activeadmin,Formtastic,我正在尝试使用active_admin实现一个具有多对多关联(with:through)的表单。我收到nil:NilClass的未定义方法“call”错误消息 我不熟悉ruby和rails 我的模型: article.rb class Article < ActiveRecord::Base has_many :tagged_articles has_many :tags, :through => :tagged_articles, :source => :tag, :

我正在尝试使用active_admin实现一个具有多对多关联(with:through)的表单。我收到nil:NilClass的未定义方法“call”错误消息

我不熟悉ruby和rails

我的模型:

article.rb

class Article < ActiveRecord::Base
  has_many :tagged_articles
  has_many :tags, :through => :tagged_articles, :source => :tag, :class_name => TaggedArticle
  accepts_nested_attributes_for :tags
end
class TaggedArticle < ActiveRecord::Base
  belongs_to :article
  belongs_to :tag
end
class Tag < ActiveRecord::Base
  has_many :tagged_articles
  has_many :articles, :through => :tagged_articles
end
类文章:taged\u文章,:source=>:tag,:class\u name=>TaggedArticle
接受:标记的\u嵌套\u属性\u
结束
标记文章.rb

class Article < ActiveRecord::Base
  has_many :tagged_articles
  has_many :tags, :through => :tagged_articles, :source => :tag, :class_name => TaggedArticle
  accepts_nested_attributes_for :tags
end
class TaggedArticle < ActiveRecord::Base
  belongs_to :article
  belongs_to :tag
end
class Tag < ActiveRecord::Base
  has_many :tagged_articles
  has_many :articles, :through => :tagged_articles
end
class TaggedArticle
标记.rb

class Article < ActiveRecord::Base
  has_many :tagged_articles
  has_many :tags, :through => :tagged_articles, :source => :tag, :class_name => TaggedArticle
  accepts_nested_attributes_for :tags
end
class TaggedArticle < ActiveRecord::Base
  belongs_to :article
  belongs_to :tag
end
class Tag < ActiveRecord::Base
  has_many :tagged_articles
  has_many :articles, :through => :tagged_articles
end
class标记:标记\u文章
结束
看法

\u form.html

<%= semantic_form_for @article, :html => {:id => "new_article",
                                          :novalidate => "novalidate"} do |f| %>
{:id=>“新文章”,
:novalidate=>“novalidate”}do | f |%>
app/admin/article.rb(活动管理文件)

ActiveAdmin.register文章do
表单部分:“表单”
表格do | f|
f、 有多个:标记,标题:“标记”,允许销毁:真,新记录:真
f、 行动
结束
表演
#呈现app/views/admin/posts/_some_partial.html.erb
渲染“预览”
结束
#许可证参数:标题、文本、,
#标签\属性:[:名称]
许可证
允许=[:标题,:文本,
标签\属性:[:名称]]

#允许如果在表单字段中使用
allow\u destroy:true
,则还需要在
接受嵌套的属性\u上使用它

class Article < ActiveRecord::Base
  has_many :tagged_articles
  has_many :tags, :through => :tagged_articles, :source => :tag, :class_name => TaggedArticle
  accepts_nested_attributes_for :tags, allow_destroy: true
end
类文章:taged\u文章,:source=>:tag,:class\u name=>TaggedArticle
接受:标记的\u嵌套\u属性\u,允许\u销毁:true
结束

我认为nilclass错误的原因是嵌套表单没有指定字段

添加

f.has_many :tags do |cf|                                                                                                                                                                         
  cf.input :tag, :label => "Tag"                                                                                                                                                                                                                            
end
解决了班级问题

最后,下面的代码成功了。在这种特殊情况下,不需要wirte_form.html.erb

form do |f|                                                                                                                                                                                                                                                   
  f.has_many :tags do |cf|                                                                                                                                                                         
    cf.input :tag, :label => "Tag"                                                                                                                                                                                                                            
  end                                                                                                                                                                                                                                                         
  f.actions                                                                                                                                                                                                                                                   
end

发布完整的堆栈跟踪。我编辑了日志并添加了应用程序和完整跟踪。