私の Rails API には、モデルを更新するための次の行があります。ご覧のとおり、多くのパラメーターを受け入れます。しかし、これについていくつかの質問があり、現在のドキュメントでは答えられません...
@updated_special_deal.update_attributes(:category => params[:category], :title => params[:title], :excerpt => params[:excerpt], :description => params[:description], :original_price => params[:original_price], :deal_price => params[:deal_price], :provider => params[:provider], :product_link => params[:product_link], :conditions => params[:conditions], :phone_number => params[:phone_number], :street => params[:street], :city => params[:city], :postal_code => params[:postal_code], :state => params[:state], :country => params[:country], :expires => params[:expires], :image_file_name => params[:image_file_name], :image_content_type => params[:image_content_type], :image_file_size => params[:image_file_size], :image_updated_at => params[:image_updated_at], :public => true)
外部クライアントアプリ経由でこの PUT リクエストを試行すると。私はこの応答を以下に得ます...
Started PUT "/api/v1/1/special_deals/47?title=The+greatest+deal+ever" for 127.0.0.1 at 2013-04-12 14:39:15 -0700
Processing by Api::V1::SpecialDealsController#update as JSON
Parameters: {"title"=>"The greatest deal ever", "servant_id"=>"1", "id"=>"47"}
ActiveRecord::RecordInvalid - Validation failed: Provider can't be blank, Description can't be blank:
確かに、私はモデルにそれらのルールを書きました。ただし、Provider 属性または Description 属性を渡そうとはしていません。それで、ここで何が起こっているのですか?
- 上記の .update_attributes 構文では、PUT リクエストに含まれていないパラメーターはどうなりますか? モデルを空白の値で更新しようとするだけですか?
- その場合、update_attributes を使用する場合、モデルのすべての属性の値を送信する必要がありますか?
編集 質問を言い換える: PUT リクエストに含まれる属性のみを更新するように update_attributes を作成するにはどうすればよいですか?