Thanks to everyone for taking the time to assist me with this problem. As a newcomer to Ruby, the solution may be quite simple. I have developed an API that facilitates communication between Ruby and Angularjs. Here is the API:
class EntriesController < ApplicationController
respond_to :json
protect_from_forgery
def index
respond_with Entry.all
end
def show
respond_with Entry.find(params[:id])
end
def create
respond_with Entry.create(params[:entry])
end
def update
respond_with Entry.update(params[:id], params[entry])
end
def destroy
respond_with Entry.destroy(params[:id])
end
end
My AngularJS controller code is as follows:
@app = angular.module("angRails",["ngResource", "ngMaterial", "ngAnimate", "ngAria"]);
@mainCTRL = ["$scope", "$resource", ($scope, $resource) ->
Entry = $resource("/entries/:id", {id: "@id"}, {update: {method: "PUT"}})
$scope.newName = "";
$scope.entries = Entry.query();
$scope.addEntry = ->
unless $scope.newName is ""
entry = Entry.save($scope.newName)
console.log(JSON.stringify(entry));
$scope.entries.push(entry);
console.log("add Entry function");
$scope.newName = "";
]
app.controller("mainCTRL", mainCTRL);
The $scope.entries = Entry.query();
line works perfectly fine, but there seems to be an issue with creating entries. The error message received is:
POST http://localhost:3000/entries 500 (Internal Server Error)
ActiveModel::ForbiddenAttributesError in EntriesController#create
ActiveModel::ForbiddenAttributesError
Extracted source (around line #14):
12
13 def create
14 respond_with Entry.create(params[:entry])
15 end
I am unsure of the reason behind this error. Any help provided would be greatly appreciated. Thank you!