5

I'm developing some API for my mobile app, and I want to add some action to render CSRF token in JSON. I know that there is helper csrf_meta_tags for HTML views, but how can I do it in controller? Thanks in advance.

2 Answers 2

4

You can use form_authenticity_token in the controller. It uses session[:_csrf_token] as suggested by @user123, and also initialize it if it has not been done yet (see source).

Sign up to request clarification or add additional context in comments.

Comments

2

use the value in

session[:_csrf_token]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.