I'm new to angularJS and Rails,and I tried to building a Rails application with AngularJS
and now, I want to do a POST request to sent data insert database
Activity Controller
def create
@activity = Activity.new(params[:activity])
respond_to do |format|
if @activity.save
format.html {redirect_to activities_url}
format.json { render activities_url, status: :created, location: @activity}
end
end
end
Activity Coffee JS
app = module('activity', ['ngAnimate'])
app.controller 'FormCtrl', ($scope, $http) ->
config = {
header: {
'Content-Type': 'application/json'
}
}
@test = ->
$http.post('/activities.json', {title: 'test1'}, config).success (data, status) ->
console.log(data)
console.log(status)
return
Console log
Started POST "/activities.json" for ::1 at 2016-05-04 21:06:10 +0800
Processing by ActivitiesController#create as JSON
Parameters: {"title"=>"test1", "activity"=>{"title"=>"test1"}}
Can't verify CSRF token authenticity
Completed 422 Unprocessable Entity in 2ms (ActiveRecord: 0.0ms)
I created a button of ng-click to trigger test function but I got information like console log, How can I do to fix it?