To put it simply: I need to handle the response from rails API to make something, but I need the header of response only, without any of data.

But then is not getting the response when it contains the header only.

In details:

rails Controller action:

def index
  # some logic here ...
  head :created
end

ember component action:

let adapter = getOwner(this).lookup('adapter:application');
adapter.ajax(
  adapter.buildURL('/index'), 'POST', { some_param: 'some_content' }
).then(() => { 'do something here...' });

So in this implementation { 'do something here...' } is never used. But it works successfully if change the controller-action:

def index
  render json: [], status: :created
end

but I do not need to render some of json in response.

So, the question is:

how can run code 'do something here...' for controller-action:

def index
  head :created
end

Any help is appreciated.

1 Answers

0
Lux On

why route it through the adapter at all? in general you should only use the adapter for ember-data requests.

Just use fetch (use ember-fetch if you need a polyfill)!

const res = await fetch('/index', {
  method: 'POST',
  body: JSON.stringify({ some_param: 'some_content' }),
});

console.log(res.headers.get('your-header'));