【发布时间】:2018-07-11 08:59:29
【问题描述】:
我有一个 vue.js 前端,我在其中使用 axios 向端点 /stats/:id 发出 PATCH 请求。这是我提出请求的那一行:
this.$axios.patch(ApiAddress, { data: this.rows }, {
headers: { Authorization: this.$requestHeaders.Authorization },
});
在这里您可以看到,我传递的唯一信息是密钥“数据”和通过路由器传递的“id”密钥。但是当控制器收到请求时,我看到以下内容:
{ 数据 => { 示例:“foo”},id=>#,stat=>{ 数据=> { 示例:“foo”} } }
我不知道那个“stat”参数是从哪里来的。
这是我的路线:
Rails.application.routes.draw do
post 'user_token' => 'user_token#create'
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
resources :users
resources :stats
mount Knock::Engine => "/knock"
get "profile/:id", to: 'profile#show', as: 'profile'
get "profile", to: 'profile#index'
end
这是我的统计控制器:
class StatsController < ApplicationController
before_action :authenticate_user
def update
stat = current_user.Stats.find(params[:id])
# stat.data = params['data']
param_object = stats_params
if stat.update(param_object)
render json: stat
end
end
def stats_params
params.require(:stat).permit(:data, :title, :privacy)
end
end
非常感谢任何帮助:)。
【问题讨论】:
-
您是否在浏览器开发工具中检查了请求的正文?
标签: ruby-on-rails ruby api vue.js axios