Answer the question
In order to leave comments, you need to log in
Why does POST request to ruby on rails from Advanced Rest Client not work?
The following method is described in the controller
def create
@messege = Messege.new(messege_params)
if @messege.save
render json: @messege, status: :created, location: @messege
else
render json: @messege.errors, status: :unprocessable_entity
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_messege
@messege = Messege.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def messege_params
params.require(:messege).permit(:author_id, :destin_id, :content)
end
end
Answer the question
In order to leave comments, you need to log in
If you want to send JSON, then, in fact, send JSON.
You can check JSON, for example, here: jsonformatter.curiousconcept.com
This JSON: Check
will fail.
And this one:
Rather, yes.
Plus, sometimes you need to remember that JSON, whose arguments are taken in single quotes, can be considered invalid.
This is like the most common problem when using any rest-clients - they do not translate the convenient key / value format into JSON, unfortunately.
If this does not help, then describe the error in more detail. Because Obviously, it’s not a Bad Request that is returned to you, but some kind of exception, in fact.
The require method ensures that a specific parameter is present, and if it's not provided, the require method throws an error. It returns an instance of ActionController::Parameters for the key passed into require.
messege : { author_id:1, destin_id:2, content:3}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question