2016-07-10 2 views
0

내 엠버 프론트 엔드는 다음과 같이 나에게 데이터를 전송한다 : 여기준 레일 API와 타다 남은 제출에

{ 
    "data":{ 
     "attributes":{ 
     "title":"asd", 
     "description":"asd" 
     }, 
     "relationships":{ 
     "users":{ 
      "data":[ 
       { 
        "type":"users", 
        "id":"1" 
       } 
      ] 
     } 
     }, 
     "type":"cards" 
    } 
} 

, 나는 새로운 card 만들 때 carduser 사이에 연결하려는.

응용 프로그램/컨트롤러/cards_controller.rb

def create 
    @card = Card.new(card_params) 

    if @card.save 
    @card.users << User.find(params[:data][:relationships][:users][:data]) if params[:data][:relationships][:users][:data] 

    render json: @card 
    else 
    render json: @card, :status => 422 
    end 
end 

private 

def card_params 
    params.require(:data).require(:attributes).permit(:title, :description) 
end 

레일 끝에서 오류가이 같은 것입니다 :

DEPRECATION WARNING: Method to_a is deprecated and will be removed in Rails 5.1, as `ActionController::Parameters` no longer inherits from hash. Using this deprecated behavior exposes potential security problems. If you continue to use this method you may be creating a security vulnerability in your app that can be exploited. Instead, consider using one of these documented methods which are not deprecated: http://api.rubyonrails.org/v5.0.0/classes/ActionController/Parameters.html (called from create at /Applications/AMPPS/www/development/ideast/hub/hub-server/app/controllers/cards_controller.rb:16) 
Completed 500 Internal Server Error in 24ms (ActiveRecord: 3.4ms) 

NoMethodError (undefined method `join' for #<ActionController::Parameters:0x007f9b5549e380> 
Did you mean? JSON): 

리포 링크 : 당신이 할 수 있어야한다 생각 https://github.com/ghoshnirmalya/hub-server

답변

1

올바른 데이터 형식을 보내도록 Ember 어댑터를 사용자 정의하십시오.

그러나, 여기에 내가 아마 현재의 문제를 해결 갈 거라고 방법 :

** user_params 방법은 너무 깨끗하지, 난 아마 그것을 처리하는 청소기 방법을 찾아야 할 것입니다.

def create 
    @card = Card.new(card_params) 

    if @card.save 
    @card.users << User.find(user_params) 

    render json: @card 
    else 
    render json: @card, :status => 422 
    end 
end 

private 

def user_params 
    params.require(:data).require(:relationships).require(:users).permit(data: [:id]).require(:data).map(&:values) 
end 

def card_params 
    params.require(:data).require(:attributes).permit(:title, :description) 
end 
관련 문제