0

Api for Rails 3 create アクションを curl で手動でテストしていますが、取得し続けInternal server error(500)ます。私は製品モデルを持っており、これがコントローラーの作成アクションと私が試したコマンドです....

#command
curl -i -H "Accept: application/json"  -X POST -d "product[product_name]=dvd"  http://localhost:3000/api/products  

#controller
module Api  
  class ProductsController < ApplicationController
    respond_to :json

     def create
       @product = Product.new(params[:product])
       respond_to do |format|
         if @product.save
           format.html { redirect_to @product, notice: 'Product was successfully created.' }
           format.json { render json: @product, status: :created, location: @product }
         else
           format.html { render action: "new" }
           format.json { render json: @product.errors, status: :unprocessable_entity }
         end
       end
     end
   end
 end

ここで何が欠けていますか?前もって感謝します。

4

1 に答える 1

1

MassAssignmentSecurity エラーに基づくと、モデルで product_name フィールドにアクセスできるようにするだけでよいようです。

class Product < ActiveRecord::Base
  attr_accessible :product_name
  #... other code...
end
于 2012-11-20T22:39:20.720 に答える