Setting up rails session in ajax message

Kind of a weird problem, hope someone can help me.

I want to establish a session in my rails controller which I hit through a jquery ajax post.

Its a regular rails form that I post via ajax

 $.post($(this).attr('action'), $(this).serialize(), function(data){

 }, 'json');

which gets into the wire controller

def create
    @lead = Lead.new(params[:lead])
    @lead.save!

    if @lead.save
      session[:lead] = "#{@lead.id}"
    end

  end

however, the session does not seem to be set to an ajax call.

Anyone have any ideas on this?

+3
source share
2 answers

In fact, you saw how creation is called in the controller (it appeared in the log)?

BTW: you call save () twice, but this is not a problem (calling save several times returns true each time the save is successful).

0
source

, , , .

, CSRF, , XHR , (, , ).

0

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


All Articles