0

I have a controller method like this. (in home controller)

def verify_email
 // some logic
 format.json { render json: {  message: message  } }
 format.js

end

I know that, we can call this method, by using remote true like below. as this is a JS method.

<%= form_for(resource, as: resource_name, url: home_verify_email_path, html: { id: "signup-form" }, remote: true, data: { controller: "validations", validations_target: "form" }) do |f| %>

as it is the form, I can use remote true, and it's working perfectly fine. but how can i call this method from the controller (like where and how can I use remote true in the following scenario?)

 in applicatin_controller

def after_sign_in_path_for(resource)
    if user.email_verified?
       redirect_to dashboard_url
    else
      home_verify_email_path (how can i call this url as JS request here in this particular case, i mean where we can use remote true here ? )
    end
  end

can someone help me with this problem?

John
  • 1,273
  • 3
  • 27
  • 61
  • I'd move whatever is inside format.json (the { render json: { message: message } }) into its own method and then have both places call this method. – Joel Blum Apr 13 '21 at 18:59
  • Not sure if it works but ...`home_verify_email_path(format: :js)` ? – razvans Apr 13 '21 at 20:00
  • This has some pretty bright and clear signs of being an [XY problem](https://meta.stackexchange.com/questions/66377/what-is-the-xy-problem). Specifically because ApplicationController is just the superclass for your controllers. You never really call methods from there. Neither should you ever add actions to it that respond to HTTP requests as your adding it to all your controllers. Instead of asking about what you think is the solution tell us what the actual unlying problem is that this code intends to solve. – max Apr 13 '21 at 20:49
  • after user signup form., iam showing a popup where, im dispalying a message please confirm, your email id then only click continue. if user is not confirming email and click on continue, then popup dispalays a error meesage untill you confirm the email id you cant continue. then the user is not clicking continue. and he wants to login from a incognito window. then i want to show the confirmation popup up where he left previously – John Apr 13 '21 at 21:07

0 Answers0