Rails 5 accepts_nested_attributes_for JSON POST로 처리 할 수없는 엔티티 가져 오기

맷 롱

중첩 된 속성을 보낼 수있는이 모든 설정 권한이 있다고 생각하지만 처리 할 수없는 엔티티 422가 계속 표시되지만 오류 메시지는 표시되지 않습니다. 구성하는 방법은 다음과 같습니다.

scouting_report.rb

class ScoutingReport < ApplicationRecord
    has_many :scouting_report_details
    accepts_nested_attributes_for :scouting_report_details, :allow_destroy => true
end

scouting_report_detail.rb

class ScoutingReportDetail < ApplicationRecord
    belongs_to :scouting_report
end

scouting_reports_controller.rb

def scouting_report_params
  params.require(:scouting_report).permit(
    :customer_id, 
    :report_date, 
    :crop_id, 
    :wind_speed, 
    :wind_speed_direction, 
    :wind_speed_degree, 
    :temperature, 
    :sky, 
    :crop_growth_stage, 
    :crop_condition_comments, 
    :stand_count, 
    :irrigation_comment, 
    :crop_water_use, 
    :crop_water_use_units, 
      scouting_report_details_attributes: [
        :id, 
        :action, 
        :disorder_id, 
        :disorder, 
        :identifiaction, 
        :lon, 
        :level, 
        :lat, 
        :scouting_report_id])
end

다음은 스키마에서 데이터가 표시되는 방식입니다.

  create_table "scouting_reports", force: :cascade do |t|
    t.integer  "customer_id"
    t.datetime "created_at",              null: false
    t.datetime "updated_at",              null: false
    t.datetime "report_date"
    t.integer  "crop_id"
    t.string   "wind_speed"
    t.string   "wind_speed_direction"
    t.string   "wind_speed_degree"
    t.string   "temperature"
    t.string   "sky"
    t.string   "crop_growth_stage"
    t.text     "crop_condition_comments"
    t.string   "stand_count"
    t.text     "irrigation_comment"
    t.string   "crop_water_use"
    t.string   "crop_water_use_units"
  end

  create_table "scouting_report_details", force: :cascade do |t|
    t.string   "disorder"
    t.integer  "disorder_id"
    t.string   "level"
    t.string   "action"
    t.string   "identifiaction"
    t.string   "lat"
    t.string   "lon"
    t.datetime "created_at",         null: false
    t.datetime "updated_at",         null: false
    t.integer  "scouting_report_id"
  end

로그는 422를보고하지만 오류는 없습니다.

시작됨 POST "/scouting_reports.json"for 127.0.0.1 at 2017-03-25 13:41:55 -0600 Processing by ScoutingReportsController # create as JSON Parameters : { "scouting_report"=> { "crop_water_use"=> "Yes. Water 사용됩니다. ","crop_water_use_units "=>"IPD ","wind_speed "=>"12 ","report_date "=>"2017-03-25T19 : 41 : 55Z ","scouting_report_details_attributes "=> [{"identifiaction " => "거기있는 것 같습니다", "action"=> "Treat", "disorder"=> "", "lon"=> "-97.989378", "level"=> "3", "lat"=> "40.875492", "disorder_id"=> 158}], "wind_speed_degree"=> "10", "sky"=> "B ","crop_growth_stage "=>"1 단계 ","온도 "=>"68 ","wind_speed_direction "=>"NW ","irrigation_comment "=>"작물은 자극을받지 않으면 관개됩니다. ","stand_count "= > "12", "crop_condition_comments"=> "조건에 대한 설명", "crop_id"=> "1234"}} (0.1ms) BEGIN (0.1ms) ROLLBACK 완료 33ms 만에 422 처리 할 수없는 엔티티 (보기 : 0.2ms | ActiveRecord : 4.4ms)"Comment about the conditions", "crop_id"=> "1234"}} (0.1ms) BEGIN (0.1ms) ROLLBACK Completed 422 Unprocessable Entity in 33ms (Views : 0.2ms | ActiveRecord : 4.4ms)"Comment about the conditions", "crop_id"=> "1234"}} (0.1ms) BEGIN (0.1ms) ROLLBACK Completed 422 Unprocessable Entity in 33ms (Views : 0.2ms | ActiveRecord : 4.4ms)

원시 JSON 페이로드

{
    "scouting_report" : {
        "crop_water_use" : "Yes. Water is used.",
        "crop_water_use_units" : "IPD",
        "wind_speed" : "12",
        "report_date" : "2017-03-25T14:45:10Z",
        "scouting_report_details_attributes" : [
            {
                "identifiaction" : "Looks like it's there",
                "action" : "Treat",
                "disorder" : "",
                "lon" : "-97.989378",
                "level" : "3",
                "lat" : "40.875492",
                "disorder_id" : 158
            }
        ],
        "wind_speed_degree" : "10",
        "sky" : "B",
        "crop_growth_stage" : "Stage 1",
        "temperature" : "68",
        "wind_speed_direction" : "NW",
        "irrigation_comment" : "The crops are irrigated if not irritated",
        "stand_count" : "12",
        "crop_condition_comments" : "Comment about the conditions",
        "crop_id" : "1234"
    }
}

다른 눈이 필요합니다. 나는 단순한 것을 놓치고 있다고 확신합니다.

inverse_of연결을 추가해보세요 .

class ScoutingReport < ApplicationRecord
  has_many :scouting_report_details, inverse_of: :scouting_report
end

class ScoutingReportDetail < ApplicationRecord
  belongs_to :scouting_report, inverse_of: :scouting_report_details
end

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

Rails best_in_place 처리 할 수없는 엔티티

분류에서Dev

처리 할 수없는 엔티티 오류 (ajax) (laravel 5.2)

분류에서Dev

하위 엔티티의 필드를 기반으로 Hazelcast 맵에서 엔티티를 가져 오는 방법

분류에서Dev

핵심 데이터 : 관련 엔티티의 속성을 기반으로 엔티티를 가져 오는 방법

분류에서Dev

Symfony2 : 사용자 엔티티에서 그룹의 역할을 가져 오지만 엔티티 내부 쿼리는 피합니다.

분류에서Dev

XSLT는 엔티티를 처리 할 수 없습니다.

분류에서Dev

PHP, Dropzone Laravel 5.1 422 (처리 할 수없는 엔티티)

분류에서Dev

LUIS는 슬래시로 복합 엔티티를 처리 할 수 있습니까?

분류에서Dev

이미지를 업로드하는 동안 처리 할 수없는 엔티티 RESTful API 레일 422 개 완료

분류에서Dev

SoapClient가 외부 엔티티를로드 할 수 없습니다.

분류에서Dev

Symfony2 다른 엔티티에있는 엔티티의 엔티티 가져 오기

분류에서Dev

데이터 스키마를 처리하려고 할 때 "엔티티를 해결할 수 없음"오류

분류에서Dev

JAX-RS의 JAXB-관계가있는 JPA 엔티티가 로그에 오류없이 JSON HTTP 500을 리턴하지 않음 (Glassfish)

분류에서Dev

봄 REST는 : 엔티티에 추가 요청 본문에서 JSON 데이터를 가져 오기

분류에서Dev

(422) ServiceStack 라우팅이있는 처리 할 수없는 엔티티

분류에서Dev

SendAsync () 반환 422 처리 할 수없는 엔터티

분류에서Dev

UTF-8로 인코딩 할 엔티티가있는 List <String>

분류에서Dev

Linq의 문자 값을 엔티티로 가져 오기

분류에서Dev

GUID 목록으로 엔티티 목록 가져 오기

분류에서Dev

이름으로 엔티티 요소 가져 오기

분류에서Dev

EF Core에서 조건 순서로 엔티티를 가져 오는 방법

분류에서Dev

JSON으로 변환 할 때 관련 엔티티가 이스케이프되는 이유는 무엇입니까?

분류에서Dev

양식 이벤트 리스너에서 기본 데이터 엔티티를 형성하도록 링크 된 엔티티를 가져올 수 없습니다.

분류에서Dev

Breeze 엔티티에있는 속성 이름 가져 오기

분류에서Dev

accepts_nested_attributes_for '보호 된 속성을 대량 할당 할 수 없음 경고'를 트리거합니다.

분류에서Dev

SpringData를 사용하여 엔티티 ID로 엔티티에서 임베디드 오브젝트 가져 오기

분류에서Dev

linq를 엔티티에 사용하여 관련 엔티티를 기반으로 레코드 가져 오기

분류에서Dev

ViewModel에 목록으로 엔티티를 추가 할 수 없습니까?

분류에서Dev

다른 엔티티 오류가있는 JPA 관리 맵핑

Related 관련 기사

  1. 1

    Rails best_in_place 처리 할 수없는 엔티티

  2. 2

    처리 할 수없는 엔티티 오류 (ajax) (laravel 5.2)

  3. 3

    하위 엔티티의 필드를 기반으로 Hazelcast 맵에서 엔티티를 가져 오는 방법

  4. 4

    핵심 데이터 : 관련 엔티티의 속성을 기반으로 엔티티를 가져 오는 방법

  5. 5

    Symfony2 : 사용자 엔티티에서 그룹의 역할을 가져 오지만 엔티티 내부 쿼리는 피합니다.

  6. 6

    XSLT는 엔티티를 처리 할 수 없습니다.

  7. 7

    PHP, Dropzone Laravel 5.1 422 (처리 할 수없는 엔티티)

  8. 8

    LUIS는 슬래시로 복합 엔티티를 처리 할 수 있습니까?

  9. 9

    이미지를 업로드하는 동안 처리 할 수없는 엔티티 RESTful API 레일 422 개 완료

  10. 10

    SoapClient가 외부 엔티티를로드 할 수 없습니다.

  11. 11

    Symfony2 다른 엔티티에있는 엔티티의 엔티티 가져 오기

  12. 12

    데이터 스키마를 처리하려고 할 때 "엔티티를 해결할 수 없음"오류

  13. 13

    JAX-RS의 JAXB-관계가있는 JPA 엔티티가 로그에 오류없이 JSON HTTP 500을 리턴하지 않음 (Glassfish)

  14. 14

    봄 REST는 : 엔티티에 추가 요청 본문에서 JSON 데이터를 가져 오기

  15. 15

    (422) ServiceStack 라우팅이있는 처리 할 수없는 엔티티

  16. 16

    SendAsync () 반환 422 처리 할 수없는 엔터티

  17. 17

    UTF-8로 인코딩 할 엔티티가있는 List <String>

  18. 18

    Linq의 문자 값을 엔티티로 가져 오기

  19. 19

    GUID 목록으로 엔티티 목록 가져 오기

  20. 20

    이름으로 엔티티 요소 가져 오기

  21. 21

    EF Core에서 조건 순서로 엔티티를 가져 오는 방법

  22. 22

    JSON으로 변환 할 때 관련 엔티티가 이스케이프되는 이유는 무엇입니까?

  23. 23

    양식 이벤트 리스너에서 기본 데이터 엔티티를 형성하도록 링크 된 엔티티를 가져올 수 없습니다.

  24. 24

    Breeze 엔티티에있는 속성 이름 가져 오기

  25. 25

    accepts_nested_attributes_for '보호 된 속성을 대량 할당 할 수 없음 경고'를 트리거합니다.

  26. 26

    SpringData를 사용하여 엔티티 ID로 엔티티에서 임베디드 오브젝트 가져 오기

  27. 27

    linq를 엔티티에 사용하여 관련 엔티티를 기반으로 레코드 가져 오기

  28. 28

    ViewModel에 목록으로 엔티티를 추가 할 수 없습니까?

  29. 29

    다른 엔티티 오류가있는 JPA 관리 맵핑

뜨겁다태그

보관