title: How to make Axios make call for json response with Rails?
body: <p>I read and found that axios will make the call for json format to an endpoint, which doesn't seem to be the case here. My endpoint looks like this:</p>
  
  <pre><code>  def create
      @form = Form.new(form_params)
      if @form.save
        respond_to do |format|
          format.html { redirect_to(@form, notice: "Form created successfully") }
          format.json { render json: {message: "Form created successfully"} }
        end
      else
        respond_to do |format|
          format.html { render 'new' }
          format.json { render json: {errors: @form.errors}, status: :unprocessable_entity }
        end
  
      end
    end
  </code></pre>
  
  <p>My axios call looks like this:</p>
  
  <pre><code>function instance() {
    return axios.create({
      headers: {'X-CSRF-Token': document.querySelector('meta[name="csrf-token"]').getAttribute('content')},
      'Content-Type':  'application/json',
      responseType: 'json'
    });
  }
  
  function post(url, data={}) {
    return instance().post(url, data)
  }
  </code></pre>
  
  <p>here is how I make the call:</p>
  
  <pre><code>post('/forms', {
            form: this.$data
          }).then((response) =&gt; {
            console.log("success");
            console.log(response.data);
          }).catch((error) =&gt; {
            console.log("errro");
            console.log(error.response);
          })
      }
  </code></pre>
  
  <p>It works if change <code>/forms</code> to <code>/forms.json</code>, any tip on how to fix this?</p>