在编辑期间添加活动管理员评论

Bot*_*Bot 6 activeadmin ruby-on-rails-4

我正在尝试添加ActiveAdmin::Comment到我的Member编辑中.我已经能够通过添加ARB和部分来做到这一点

#_comments.html.arb
active_admin_comments_for(resource)
Run Code Online (Sandbox Code Playgroud)

这显示正常,但当我输入文本然后按添加注释按钮,实际上没有添加注释,它只是返回到显示屏幕.

我想要做的是在那里得到评论,但没有添加评论按钮.我想按Update Member按钮添加评论.这样,对成员所做的任何更改都将与注释一起保存.

有没有办法让它添加Update Member按钮添加注释?

编辑:

我也试过在我的模型中添加一个关系

#model
has_many :comments, as: :resource, dependent: :destroy, class_name: 'ActiveAdmin::Comment'
accepts_nested_attributes_for :comments, reject_if: :reject_comment


# members.rb - form
f.inputs "Add A Comment" do
  f.semantic_fields_for :comments, ActiveAdmin::Comment.new do |c|
    c.inputs :class => "" do
      c.input :resource_id, :input_html => { :value => "1" }, as: :hidden
      c.input :resource_type, :input_html => { :value => "Member" }, as: :hidden
      c.input :namespace, :input_html => { :value => :admin }, as: :hidden
      c.input :body, :label => "Comment"
    end
  end
end
Run Code Online (Sandbox Code Playgroud)

但是,即使使用允许的参数,它仍然不能作为评论保存.

Bot*_*Bot 4

我最终终于让这个工作了。

模型/成员.rb

has_many :comments, as: :resource, dependent: :destroy, class_name: 'ActiveAdmin::Comment'
accepts_nested_attributes_for :comments, reject_if: :reject_comment

def reject_comment(comment)
    return comment['body'].blank?
end
Run Code Online (Sandbox Code Playgroud)

应用程序/成员.rb

# in the controller section of controller do
def update(options={}, &block)
  params[:member][:comments_attributes]['0']['namespace'] = 'admin'
  params[:member][:comments_attributes]['0']['author_id'] = current_admin_user.id
  params[:member][:comments_attributes]['0']['author_type'] = 'AdminUser'
  # This is taken from the active_admin code
  super do |success, failure|
    block.call(success, failure) if block
    failure.html { render :edit }
  end
end

# in the form portion
f.inputs "Add A Comment" do
  f.semantic_fields_for :comments, ActiveAdmin::Comment.new do |c|
    c.inputs :class => "" do
      c.input :body, :label => "Comment", :input_html => { :rows => 4 }
    end
  end
end
Run Code Online (Sandbox Code Playgroud)

这允许我有一个名为的字段Comment,如果我想在编辑时添加评论,我可以这样做并在按下按钮Member时保存评论f.actionsUpdate Member