mercredi 4 mai 2016

Rails: include code in view immediately after sign_in through devise

I'm using a js live chat widget on my rails site and I want to add a little javascript to my template after somebody signs in (it's basically telling me I've got one of my users of a particular type looking at the site).

I'm thinking that

after_sign_in_path_for 

Seems like the right place, but how do I pass a parameter (e.g.

{new_session:true}

) to a method that looks like this:

def after_sign_in_path_for(resource)
  sign_in_url = new_user_session_url
  if request.referer == sign_in_url
    super
  else
    stored_location_for(resource) || request.referer || root_path
  end
end

i.e.

root_path(new_session:true)

is straightforward, but what on earth do I do with the super, stored_location_for and request.referer...?

Seems a really ugly way to do it, in any case...

Any better ideas?

Is there a sensible way to do this in devise. e.g.

-if current_user.just_signed_in?
  :javascript
    _blah_de_blah.blah{blah;}

Aucun commentaire:

Enregistrer un commentaire