Auf Vorlage, mein Ember Frontend sendet mir Daten wie folgt aus:Mitarbeiter Schienen api und ember
{
"data":{
"attributes":{
"title":"asd",
"description":"asd"
},
"relationships":{
"users":{
"data":[
{
"type":"users",
"id":"1"
}
]
}
},
"type":"cards"
}
}
Hier möchte ich zwischen einem card
und einem user
assoziieren, wenn ein neuer card
erstellt wird.
app/controllers/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
Der Fehler in der Rails Ende so etwas wie dieses:
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):
Repo Link: https://github.com/ghoshnirmalya/hub-server