2016-12-26 70 views
0

我正在向邮递员发送请求,而且我的避难所参数一直保持为空,即使我已将其格式化为使遮蔽参数包含正确地形成数据。如果我缺少任何东西,请帮助我。ActionController :: ParameterMissing(参数丢失或值为空:避难所):

class Api::V1::SheltersController < ApplicationController 

    def index 
    @shelters = Shelter.all.order(:id).reverse 
    respond_with @shelters 
    end 

    def show 
    @shelter = Shelter.find(params[:id]) 
    respond_with @shelter 
    end 

    def create 
    @shelter = Shelter.new(shelter_params) 
    if @shelter.save 
     render json: @shelter, status: 201 
    else 
     render json: { errors: @shelter.errors.full_messages }, status: 422 
    end 
    end 


    private 

    def shelter_params 
     params.require(:shelter).permit(:name, :address, :phone, :beds) 
    end 

end 

数据我通过邮差送

shelter : { 
    name : "Pee's Shelter", 
    address : "Pee's Address", 
    phone : "(236)817-4853", 
    beds : 5 
} 

请求信息我看到铁轨页面上

参数:

{“避难所:{\ n \ t \ tname:\“小便的住处\”,\ n \ t \ t地址:\“小便的地址\”,\ n \ t \ tphone:\“(236)817-4853 \”,\ n \ t \ tbeds: 5 \ n} \ n“=> nil,”subdomain“=>”api“,”format“=>:json}

+0

你如何在邮递员中发送参数?原始的,表单数据还是x-www-form-urlencoded? – mokayode

+0

我把它作为Raw发送 –

+0

2016-12-26 08:14:42 -0800 开始POST“/ shelters”for 127.0.0.1处理方法Api :: V1 :: SheltersController#create as JSON 参数:{“shelter :{\ n \ t \ tname:\“Pee's Shelter \”,\ n \ t \ taddress:\“Pee's Address \”,\ n \ t \ tphone:\“(236)817-4853 \”,\ n \ t \ tbeds:5 \ n} \ n“=> nil,”subdomain“=>”api“} 在1ms内完成400次错误的请求(ActiveRecord:0.0ms) –

回答

1

您的密钥设定为:

"shelter : {\n\t\tname : \"Pee's Shelter\",\n\t\taddress : \"Pee's Address\",\n\t\tphone : \"(236)817-4853\",\n\t\tbeds : 5\n} \n" 

和你的那个键值为=> nil

字符串之前取出"

更确切地说:不要将您的住所和所有钥匙创建为一个字符串。

+0

我也曾在它没有它设置为JSON(application/json)谢谢 –

相关问题