dimanche 13 décembre 2015

Invalid Authenticity Token on Post

I am using devise for sign up and login. My routes.rb looks like this.

get 'profile' => 'profile#get_profile'
post 'profile' => 'profile#create_profile'

And my profile controller looks like this:

def get_profile
    render json: {user: current_user}, status: :ok
end

def create_profile
    render json: {user: current_user}, status: :ok
end

Yeah, I'm rendering the same output for testing. When I run http://localhost:3000/user/profile using GET it's returning the expected output. But when same URL using POST it's throwing error saying: ActionController::InvalidAuthenticityToken in User::ProfileController#create_profile. Now, when I change POST to GET in route and run same URL using GET then again it printing the expected result i.e. session data. I'm new to rails so unable to figure this out. Please help me. Thanks.

Aucun commentaire:

Enregistrer un commentaire