How can I implement cookieless flash messages in Rails?

I am developing a facebook application, so I cannot rely on cookies because of P3P (privacy settings project), and yes, it’s a hell of a pain (see slides 18 and 19 on this slide show about Rails and Facebook applications for its image ) ...

In the facebook application, each cookie, from the point of view of browsers, is a third-party cookie . And many browsers block them by default.

So my question is: how can I use flash messages without relying on cookies?

UPDATE:

I changed session_store.rband DB accordingly. Sessions are now stored in the database, but flash messages still rely on cookies ... Any idea, please?

UPDATE # 2:

I finally found a workaround, see my answer below. It would be best to do ajax everything (according to the above slide show), but as a quick solution, my solution should work.

+3
source share
2 answers

Finally, I found a workaround that implements my own (simple) flash messages and passing them through the parameters from one request to another.

First of all, I rewrote default_url_optionsin application_controller.rbto add a: my_flash param to each request:

def default_url_options 
  { :my_flash => @my_flash }
end    

Then always in application_controller.rbI wrote my_flash_from_paramsbefore_filter to set the variable @my_flash:

def my_flash_from_params
  @my_flash = params[:fb_flash]
end 

, _my_flash.html.erb partial application.html.erb

<div class="my_flash">
  <%= my_flash %>
</div>  

:

 <%= render :partial => "layouts/my_flash", :locals => {:my_flash => @my_flash} if @my_flash %>

, . default_url_options.

+3

Flash- . , - -, , . , config/initializers/session_store.rb .

:

0

Source: https://habr.com/ru/post/1709050/


All Articles