the_
the_

Reputation: 1173

Rails API Create Issue

api application that has a create method that looks like:

# POST /posts
# POST /posts.json
def create
    @post = Post.new(params[:post])

    if @post.save
      render json: @post, status: :created, location: api_v1_post_path(@post)
    else
      render json: @post.errors, status: :unprocessable_entity
    end
end

and then I use a curl command like:

curl --data "name=test" http://0.0.0.0:3000/api/v1/posts

which creates a post, but without the name = test like it should be. Thanks for all help!

Upvotes: 0

Views: 74

Answers (2)

Rajeev Sharma
Rajeev Sharma

Reputation: 1555

curl -H "Content-Type: application/json" -X POST -d '{"post": {"name":"test"}' http://localhost:3000/api/v1/posts

Upvotes: 0

Sachin Singh
Sachin Singh

Reputation: 7225

try this out

curl --data "post[name]=test" http://0.0.0.0:3000/api/v1/posts

Upvotes: 5

Related Questions