How to Use Session Object in Ruby on Rails with React

Photo of Marcin Kornek

Marcin Kornek

Jun 3, 2016 • 1 min read

When trying to use fetch in React to GET, POST, etc., you can't use current_user in the controller because you don't have Session object available. Session returns:

#ActionDispatch::Request::Session:0x7ffc75e90a88 not yet loaded

Solution

You need to add credentials: 'include' to fetch params.

Read the explainer here: https://github.com/github/fetch#sending-cookies

Photo of Marcin Kornek

More posts by this author

Marcin Kornek

After obtaining a master’s degree in Civil Engineering and working on the construction site, Marcin...
The Future of Innovation  We’re building the new model of consulting     Discover more

We're Netguru!


At Netguru we specialize in designing, building, shipping and scaling beautiful, usable products with blazing-fast efficiency
Let's talk business!

Trusted by:

  • Vector-5
  • Babbel logo
  • Merc logo
  • Ikea logo
  • Volkswagen logo
  • UBS_Home