私はAPIのみのRails 5アプリを持っています。Rails 5はJSONをレンダリング用にレンダリングしません
私customers_controller_testは、私は理由を理解することはできません
ActionView::MissingTemplate: Missing template api/v1/customers/show, application/show with {:locale=>[:en], :formats=>[:html], :variants=>[], :handlers=>[:raw, :erb, :html, :builder, :ruby, :jbuilder]
で失敗します。
コントローラはこのようになります(足場)
# POST /customers
# POST /customers.json
def create
@customer = Customer.new(customer_params)
if @customer.save
render :show, status: :created, location: api_v1_customer_url(@customer)
else
render json: @customer.errors, status: :unprocessable_entity
end
end
# PATCH/PUT /customers/1
# PATCH/PUT /customers/1.json
def update
if @customer.update(customer_params)
render :show, status: :ok, location: api_v1_customer_url(@customer)
else
render json: @customer.errors, status: :unprocessable_entity
end
end
なぜPOSTリターンHTMLはPUTが正しくJSONを返すときですか?
テストでは、この変更に細かい渡し:
# POST /customers
# POST /customers.json
def create
@customer = Customer.new(customer_params)
if @customer.save
render json: 'show', status: :created, location: api_v1_customer_url(@customer)
else
render json: @customer.errors, status: :unprocessable_entity
end
end
はそれを説明することができ、誰ですか?
:http://stackoverflow.com/a/6519357/1062276 – ringe