class Api::V1::ClientsController < ::ApplicationController
def index
respond_with @clients
end
def show
respond_with @client
end
def create
@client.save
respond_with @client
end
def update
@client.update_attributes(client_params)
respond_with @client
end
def destroy
@client.destroy
respond_with @client
end
private
def client_params
params.require(:client).permit(:name, :user_ids => [])
end
end
And here is my spec output:
Api::V1::ClientsController
GET index
returns a list of clients
GET show
returns an existing client
POST create
creates a new client (FAILED - 1)
PUT update
updates an existing client
DELETE destroy
destroys an existing client
Failures:
1) Api::V1::ClientsController POST create creates a new client
Failure/Error: post :create, {:client => client.attributes}
NoMethodError:
undefined method `client_url' for #<Api::V1::ClientsController:0x000000051afea0>
# ./app/controllers/api/v1/clients_controller.rb:12:in `create'
# ./spec/controllers/api/v1/clients_controller_spec.rb:30:in `block (4 levels) in <top (required)>'
# ./spec/controllers/api/v1/clients_controller_spec.rb:29:in `block (3 levels) in <top (required)>'
Finished in 0.83597 seconds (files took 5.88 seconds to load)
5 examples, 1 failure
Notice how only #create fails with that undefined method error.
This is a rails 4.2 + rails-api application. I'm just stumped why create would fail here, if update and everything else works.
Anyone seen this before? Any ideas ?
Routes look like:
namespace :api, :constraints => {:format => 'json'} do
namespace :v1 do
resource :home, :only => [:show]
resources :users, :except => [:new, :edit]
resources :clients, :except => [:new, :edit]
end
end
--
Kind regards.
Jean le Roux
Yardmaster
mobile: +27 84 606 5950
Please consider the environment before printing this email or any related attachments.