I am creating a project in Ruby on Rails, where I create a cry with the following route in postman:
POST:http://localhost:3000/api/yells
{
"user_id":"1",
"title":"caneca",
"desciption":"beber",
"yell_type":"oferta",
"price":"20,00",
"categories":[{"name":"porcelana"}]
}
Controller #create:
def create
#@yell = Yell.new(yell_params.except(:categories))
@yell = Yell.new({title: params[:title], desciption: params[:desciption], price: params[:price], user_id: params[:user_id], yell_type: params[:yell_type]})
Array(params[:categories]).each do |rel|
@category = Category.find_by_name(rel[:name])
if @category
#only creates the relationship
else
@yell.categories.build(name: rel[:name]) #creates the relationship and category
end
end
if @yell.save
render json: @yell, status: :created, location: api_yell_path(@yell)
else
render json: @yell.errors, status: :unprocessable_entity
end
end
I'm doing a project with a friend of mine who is doing the frontend, and when he tests on his machine by postman, replacing localhost
with my ip
, creates a yell
and categories, but with all empty values.
I suppose it's because params[:values]
is coming null, but it was not to come. Because in my machine it works and creates everything right. It still succeeds on the%% routes by pulling everything right. Is there something I have to configure on the server or something else on the routes, or in the postman?
Someone can help me, I really have no idea how to solve this problem.