나는 hippa를 준수하는 앱을 가지고 있는데, 그 중 일부로 중첩 된 리소스/커밋 시스템으로 AA 코멘트를 사용하고자한다. 주석이 없으면 작성 또는 갱신을 거부해야합니다. 다른 중첩 된 리소스가 작동합니다 (중첩 된 리소스를 저장하는 중첩 포함). 다음은 업데이 트에서 작동하지만 새롭지는 않습니다 - 새것입니다. comments.resource는 비워 둘 수 없다는 오류가 발생합니다.ActiveAdmin이 커밋 시스템으로 코멘트
허용 매개 변수 내에 comments_attributes가 있습니다.
ActiveAdmin.register Prescription do
menu :parent => "Treatments", :priority => 2
permit_params :treatment_id, :hours, :summary, :product_id, :prescription_date, prescribed_tensions_attributes: [:id, :location, :force, :position, :prescription_id, :created_at, :_destroy], comments_attributes: [:id, :namespace, :body, :resource_id, :resource_type, :author_id, :author_type]
before_filter :only => [:show, :destroy, :edit, :update] do
# @prescription = Prescription.unscoped.includes(:prescribed_tensions).find(params[:id])
@prescription = Prescription.unscoped.includes(:product, :prescribed_tensions, :patient, :doctors).find(params[:id])
end
form do |f|
f.inputs "Prescribed Dose" do
f.input :treatment, :as => :select, input_html: {class: 'select2able'}
f.input :prescription_date, as: :date_time_picker
f.input :hours
f.input :summary, :as => :rich, :config => { :width => '79%', :height => '150px' }
f.has_many :prescribed_tensions, :allow_destroy => true do |g|
g.input :location, :as => :select, input_html: {class: 'select2able'}, collection: BaseProduct.locations
g.input :force
g.input :position
end
end
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
f.actions
end
controller do
def setup_comments
klassname = self.resource_class.name.underscore
if params[klassname][:comments_attributes]['0']['body'].blank?
err = "A comment must be added to #{params[:action]} this #{klassname}."
else
params[klassname][:comments_attributes]['0']['namespace'] = 'admin'
params[klassname][:comments_attributes]['0']['author_id'] = current_admin_user.id
params[klassname][:comments_attributes]['0']['author_type'] = 'AdminUser'
end
if !err.nil?
params[:error] = err
end
return
end
def update(options={}, &block)
setup_comments
# save resource
if params[:error].nil?
super
if resource.errors.any?
params[:error] = resource.errors.full_messages.first
end
end
# see if any error messages
if !params[:error].nil?
redirect_to({ action: 'edit' }, alert: params[:error])
end
end
def create(options={}, &block)
setup_comments
if params[:error].nil?
super
if resource.errors.any?
params[:error] = resource.errors.full_messages.first
end
end
if !params[:error].nil?
redirect_to({ action: 'index' }, alert: params[:error])
end
end
end
end
그리고 모델/prescription.rb 내
: 위의와class Prescription < ActiveRecord::Base
belongs_to :treatment
has_one :product, through: :treatment
has_one :patient, through: :product
has_many :doctors, through: :patient
has_many :prescribed_tensions, dependent: :destroy
accepts_nested_attributes_for :prescribed_tensions, :allow_destroy => true
has_many :comments, as: :resource, dependent: :destroy, class_name: 'ActiveAdmin::Comment'
accepts_nested_attributes_for :comments
def to_s
"#{self.prescription_date.strftime('%Y-%m-%d')} : #{self.product}"
end
end
내가 얻을 : 나뿐만 아니라
#<Prescription:0x007fb402700f90
id: nil,
hours: 12,
summary: "",
prescription_date: Mon, 15 May 2017 09:31:00 EDT -04:00,
created_at: nil,
updated_at: nil,
treatment_id: 6>,
@details={:"comments.resource"=>[{:error=>:blank}]},
@messages={:"comments.resource"=>["can't be blank"]}>
을 시도하고있어 여기에 관리자/prescription.rb입니다 (예 : @ prescription = Prescription.new (permitted_params [: 처방전]) 그리고 @comment를 구축 할 때도 마찬가지지만, 설정하는 경우에도
@ comment.resource = @prescription - comments.prescription이 비어 있기 때문에 @prescription을 저장할 수 없습니다. @prescription이 아직 저장되지 않았기 때문에.
내가 여기에 우스운 이야기를 놓치고있다라고 확신하지만, 그것이 무엇인지에 관해 명확히하지 않고있다. ...?