Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Commands and Error Messages When Trying to POST to my table through CURL
I am trying to run this. I am able to post to the table through Rails C, so I have access from there.
curl --request POST --header "Authorization: Token token="d168c8333a2b72bf7ad7bfe4bb9c669d" --header "Content-Type: application/json" -d '{
"beer": {
"name":"UFO"
"brewery":"Harpoon"
"style":"Hefe"
"location_id":"11"
}
}' http://localhost:3000/beers
And it just hangs and never seems to hit my server. No error message or anything on the server
Rails.application.routes.draw do
post '/register' => 'auth#register'
# patch '/confirm' => 'auth#confirm'
post '/login' => 'auth#login'
delete '/logout/:id' => 'auth#logout'
resources :users, except: [:new, :edit]
resources :locations
resources :beers
end
Here is an example controller
class BeersController < OpenReadController
before_action :set_beer, only: [:update, :destroy]
# GET /beers
def index
@beers = Beer.all
render json: @beers
end
# GET /beers/1
def show
@beer = Beer.find(params[:id])
render json: @beer
end
# POST /beers
def create
@beer = current_user.beers.new(beer_params)
if @beer.save
render json: @beer, status: :created, beer: @beer
else
render json: @beer.errors, status: :unprocessable_entity
end
end
# PATCH /beers/1
def update
if @beer.update(beer_params)
head :no_content
else
render json: @beer.errors, status: :unprocessable_entity
end
end
# DELETE /beers/1
def destroy
@beer.destroy
head :no_content
end
def set_beer
@beer = current_user.beers.find(params[:id])
end
def beer_params
params.require(:beer).permit(:name, :brewery, :style)
end
private :set_beer, :beer_params
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.