gpt4 book ai didi

ruby-on-rails-4 - 在编辑期间添加事件管理员评论

转载 作者:行者123 更新时间:2023-12-04 15:31:45 26 4
gpt4 key购买 nike

我正在尝试添加 ActiveAdmin::Comment到我的 Member编辑。我已经能够通过添加 ARB 和部分

#_comments.html.arb
active_admin_comments_for(resource)

这显示正确,但是当我输入文本然后按添加评论按钮时,实际上并未添加评论,它只是返回到显示屏幕。

我想要做的是在那里获取评论,但没有添加评论按钮。我想通过按 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

但是,即使使用允许的参数,它仍然不会保存为注释。

最佳答案

我最终得到了这个工作。

模型/成员.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

app/Members.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

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

关于ruby-on-rails-4 - 在编辑期间添加事件管理员评论,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39989569/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com