Reputation: 1793
I have set of external API controllers in my app. All works fine.
One of the controllers is groupings_controller.rb. Grouping is a many-to-many relationship table between users and groups.
class Api::V1::GroupingsController < ApplicationController
def create
@group = Group.find_by_id(params[:grouping][:group_id])
@grouping.current_user = current_user
@grouping = @group.groupings.build(user_id: current_user.id, group_id: @group.id)
@grouping.user_id = current_user.id
respond_to do |format|
if @grouping.save
format.html { redirect_to @grouping, notice: 'Grouping was successfully created.' }
format.json { render json: @grouping, status: :created, location: @grouping }
else
format.html { render action: "new" }
format.json { render json: @grouping.errors, status: :unprocessable_entity }
end
end
end
however when I create grouping
curl -v -H 'Content-Type: application/json' -H 'Accept: application/vnd.app.v1' -X POST http://localhost:3000/api/groupings/\?auth_token\=SH5nwhDSbsomyQCZzb8T -u "admin:secret" -d "{\"grouping\":{\"group_id\":\"1\"}}"
i got response
{"grouping":{"id":52,"user_id":null,"group_id":1}}*
Looks like it creates grouping from non-api controller. If I delete create from non-api controller, server throws error.
APP::Application.routes.draw do
namespace :api, defaults: { format: 'json' } do
scope module: :v1, constraints: ApiConstraints.new(version: 1, default: true) do
resources :groupings
end
end
resources :groupings
end
Upvotes: 1
Views: 390
Reputation: 1793
Ok , i am not attentive enough. my api controller was named gropuings_controller.rb
instead of groupings_controller.rb
. Should always check this!
Upvotes: 1