Test api

respond_with

module Api::V1
  class PhotosController < ApplicationController
    respond_to :json

    def create
      photo = photo_params
      new_photo = Photo.create(photo)
      respond_with new_photo
    end
  end
end
# Run rspec, you will get NoMethodError: undefined method `photo_url' error message

module Api::V1
  class PhotosController < ApplicationController
    respond_to :json

    def create
      photo = photo_params
      new_photo = Photo.create(photo)
      respond_with new_photo, location: url_for([:api, :v1, new_photo])
    end
    # specific the location url to resolve the error
  end
end

Reference

results matching ""

    No results matching ""