简体   繁体   中英

Run JS code after user signed in with Devise in Rails 5

I want to run some javascript code after user is logged in.

I'm using this code to redirect a user to his profile.

  def after_sign_in_path_for(resource)
    profile_path
    //call js code
  end

It's possible to accomplish this?

try below code to run some js code after signin:

def after_sign_in_path_for(resource)
    session[:js_code] = true
    profile_path
end

In profile view

<script type="text/javascript">
  $(document).ready(function(){
    <% if session.has_key?(:js_code) %>
      session.delete(:js_code)
     // write your js code here
    <% end%>

  })
</script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM