我正在建立一个应用程序,每次需要保存模型参数时都会得到回滚。
我再次检查了allowed_params属性和模型中的关系,但这似乎还可以。这是我的模型代码:
ActiveAdmin.register Ticket do
permit_params :direccion, :ticket_name, :ticket_descr, :ticket_status_id, :ticket_workflow_id,
:ticket_priority_id, :ticket_category_id, :client_id, :ticket_falta_remito, :closed,
ticket_updates_attributes: [:update_body, :es_solucion, :_destroy],
ticket_agent_ids: [],
employee_ids: []
menu label: "Reclamos"
filter :ticket_priority, label: "Prioridad"
filter :ticket_status, label: "Estado"
filter :ticket_workflow, label: "Progreso"
filter :ticket_category, label: "Categoria"
filter :created_at, label: "Fecha de Creacion"
filter :ticket_falta_remito, label: "Empleado debe remito?"
form do |f|
panel 'Reclamo' do
insert_tag(Arbre::HTML::Div, class: "map_canvas") { content_tag(:span, "Mapa") }
end
tabs do
tab 'Datos del Reclamo' do
f.inputs 'Datos del Reclamo' do
f.input :ticket_category, label: "Tipo de Reclamo", required: true
f.input :client_id, as: :search_select, label: "Cliente", required: true, fields: [:id, :direccion], display_name: 'direccion', :input_html => { id: 'client_id', data: { if: 'not_blank', action: 'callback copyField'} }
f.input :direccion, :input_html => {:geo => "formatted_address", :id => 'geocomplete'}, as: :hidden
f.input :ticket_agents, label: "Reportado por", required: true
end
f.inputs 'Detalles del Reclamo' do
f.input :ticket_name, label: "Resumen", required: true
f.input :ticket_descr, label: "Descripcion del Reclamo", required: true, :input_html => { :class => 'autogrow', :rows => 5, :cols => 20 }
end
end
tab 'Seguimiento' do
f.inputs 'Seguimiento del Reclamo' do
f.input :ticket_priority, label: "Prioridad"
f.input :ticket_workflow, label: "Categoria de Seguimiento"
f.input :employees, label: "Tecnico/s Asignado"
f.input :ticket_falta_remito, label: "Falta entrega de remito"
end
f.inputs 'Actualizaciones' do
f.has_many :ticket_updates, heading: '',
allow_destroy: true,
new_record: 'Nueva Actualizacion' do |a|
a.input :update_body, label: "Actualizacion", :input_html => { :class => 'autogrow', :rows => 5, :cols => 20 }
a.input :es_solucion, label: "Es Solucion?"
end
end
end
end
f.semantic_errors
f.actions
end
index do
end
end
// Ticket Model
class Ticket < ApplicationRecord
belongs_to :ticket_priority, optional: true
belongs_to :ticket_category
belongs_to :ticket_workflow
belongs_to :ticket_status
has_many :ticket_updates
has_and_belongs_to_many :employees, :join_table => "ticket_employee"
belongs_to :client
has_and_belongs_to_many :ticket_agents, :join_table => "ticket_ticket_agent"
accepts_nested_attributes_for :ticket_updates, allow_destroy: true
accepts_nested_attributes_for :client
accepts_nested_attributes_for :employees
accepts_nested_attributes_for :ticket_agents
end
我认为问题可能出在ticket_agent和employee模型中,因为它们是HABTM关系。请如果您需要更多信息,请告诉我,我会发布它。最后,这是日志:
Started POST "/admin/tickets" for 127.0.0.1 at 2018-06-19 11:03:38 -0300
Processing by Admin::TicketsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"M8HDaWnXog4GJdNSgZ+k1avBPrle/G51QX5f+Y0vT25ZE2HR//7ADAXJn33eH9CTA69Zaq51phD846JgLTP4KA==", "ticket"=>{"ticket_category_id"=>"1", "client_id"=>"698", "direccion"=>"Av. San Juan 2881, C1232AAK CABA, Argentina", "ticket_agent_ids"=>["", "4"], "ticket_name"=>"1313", "ticket_descr"=>"1313", "ticket_priority_id"=>"1", "ticket_workflow_id"=>"2", "employee_ids"=>["", "1"], "ticket_falta_remito"=>"0"}, "commit"=>"Crear Reclamo"}
[1m[36mAdminUser Load (0.5ms)[0m [1m[34mSELECT "admin_users".* FROM "admin_users" WHERE "admin_users"."id" = $1 ORDER BY "admin_users"."id" ASC LIMIT $2[0m [["id", 1], ["LIMIT", 1]]
[1m[36mTicketAgent Load (0.2ms)[0m [1m[34mSELECT "ticket_agents".* FROM "ticket_agents" WHERE "ticket_agents"."id" = 4[0m
[1m[36mEmployee Load (0.3ms)[0m [1m[34mSELECT "employees".* FROM "employees" WHERE "employees"."id" = 1[0m
[1m[35m (0.1ms)[0m [1m[35mBEGIN[0m
[1m[36mTicketCategory Load (0.1ms)[0m [1m[34mSELECT "ticket_categories".* FROM "ticket_categories" WHERE "ticket_categories"."id" = $1 LIMIT $2[0m [["id", 1], ["LIMIT", 1]]
[1m[36mTicketWorkflow Load (0.1ms)[0m [1m[34mSELECT "ticket_workflows".* FROM "ticket_workflows" WHERE "ticket_workflows"."id" = $1 LIMIT $2[0m [["id", 2], ["LIMIT", 1]]
[1m[36mClient Load (0.1ms)[0m [1m[34mSELECT "clients".* FROM "clients" WHERE "clients"."id" = $1 LIMIT $2[0m [["id", 698], ["LIMIT", 1]]
[1m[35m (0.1ms)[0m [1m[31mROLLBACK[0m
Rendering /Users/nicolasrsande/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/activeadmin-1.3.0/app/views/active_admin/resource/new.html.arb
[1m[36mTicketCategory Load (0.3ms)[0m [1m[34mSELECT "ticket_categories".* FROM "ticket_categories"[0m
[1m[36mClient Load (0.3ms)[0m [1m[34mSELECT "clients".* FROM "clients" WHERE "clients"."id" = $1 ORDER BY "clients"."id" ASC LIMIT $2[0m [["id", 698], ["LIMIT", 1]]
[1m[36mTicketAgent Load (0.3ms)[0m [1m[34mSELECT "ticket_agents".* FROM "ticket_agents"[0m
[1m[36mTicketPriority Load (0.3ms)[0m [1m[34mSELECT "ticket_priorities".* FROM "ticket_priorities"[0m
[1m[36mTicketPriority Load (0.2ms)[0m [1m[34mSELECT "ticket_priorities".* FROM "ticket_priorities" WHERE "ticket_priorities"."id" = $1 LIMIT $2[0m [["id", 1], ["LIMIT", 1]]
[1m[36mTicketWorkflow Load (0.3ms)[0m [1m[34mSELECT "ticket_workflows".* FROM "ticket_workflows"[0m
[1m[36mEmployee Load (0.2ms)[0m [1m[34mSELECT "employees".* FROM "employees"[0m
Rendered /Users/nicolasrsande/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/activeadmin-1.3.0/app/views/active_admin/resource/new.html.arb (492.1ms)
Completed 200 OK in 596ms (Views: 514.6ms | ActiveRecord: 3.4ms)
如果您能帮助我,我将不胜感激。谢谢。
答案 0 :(得分:1)
我有一个类似的问题,我只看到回滚而没有显示错误。
在调试阶段,例如,将byebug
放在创建/保存尝试之后,我发现此命令很有用
acl.errors.full_messages
在我的情况下,acl是我的模型的实例
答案 1 :(得分:0)
我知道了。
那是我试图保存一个未定义的属性。
谢谢。