I want to access the json for upvote in the browser like http://localhost:3000/groups.json (see code). Not having much luck, here is the relevant code.
Error: undefined local variable or method `group_params' for #
// inject $http so we can go to http://localhost:3000/groups.json in our browser and see an array of all the groups in our database
.factory('groups', ['$http', function($http){
//service body
var o = {
groups: []
};
// get all the groups in the service, groups.js
o.getAll = function() {
return $http.get('/groups.json').success(function(data){
angular.copy(data, o.groups);
});
};
o.getAll = function() {
return $http.get('/groups/upvote.json').success(function(data){
angular.copy(data, o.groups);
});
};
Rails Controller:
before_action :set_group, only: [:show, :edit, :update, :destroy, :upvote]
def upvote
@groups = Group.all
respond_to do |format|
format.html {}
format.json { render json: @groups }
end
end
Additional Methods:
def index
@groups = Group.all
respond_to do |format|
format.html {}
format.json { render json: @groups }
end
end
def set_group
@group = Group.where(params[:id])
end
Full Error:
Started GET "/groups/upvote.json" for 127.0.0.1 at 2017-03-21 21:37:22 0700
Processing by GroupsController#show as JSON
Parameters: {"id"=>"upvote"}
Group Load (0.4ms) SELECT "groups".* FROM "groups" WHERE "groups"."id" = $1 LIMIT 1 [["id", 0]]
Completed 404 Not Found in 5ms (ActiveRecord: 2.4ms)
ActiveRecord::RecordNotFound (Couldn't find Group with 'id'=upvote):
app/controllers/groups_controller.rb:131:in `set_group'
set_groupas abefore_actionforupvote, which is where I'm guessing the problem is. Can you please show the code for that method as well?