Reputation: 588
I'm building Rails 4 application. It's mostly json api so I'm also using rails-api gem in my app. I have ApiControllers which extends ActionController::API.
Now I need to add some classic server render HTML templates. Controllers for those renders extends ActionController::Base.
I have problem, that rails are not setting cookie in browser, so my sessions are not working at all. I tried to start new Rails 4 app and sessions in it and everything works fine. I don't know why it is not working in my application. set-cookie header is missing. Any ideas?
Upvotes: 3
Views: 4591
Reputation: 198
Changing config.api_only = false
works fine but it is not the best solution in case you are looking to use the API version and still implement functionalities like cookies and sessions it is possible by just specifying that you want to use those in application.rb
like this:
config.api_only = true
config.middleware.use ActionDispatch::Cookies
config.middleware.use ActionDispatch::Session::CookieStore
Upvotes: 6
Reputation: 588
rails-api change some application configuration. I have to add this code in config/application.rb
config.api_only = false
THX to this thread: Adding cookie session store back to Rails API app
Upvotes: 2