Given I have the following routes defined in routes.rb
get "signup" => "users#new"
post "signup" => "users#create"
and the following condition in my erb view
<%if current_page?(login_path) or current_page?(signup_path)%>
<p> NOW YOU'RE IN</p>
<% end %>
How do I get both the GET and POST path to be recognized by current_page? Now whenever it's in users#create, the p tag does not show. I am assuming it's because the route defined /signup as a get for users#new, and post is something else entirely.
I've tried the following, but it does not appear to work
<%if current_page?(login_path) or current_page?(signup_path) or current_page?(controller: "users", action: "create")%>
<p> NOW YOU'RE IN</p>
<% end %>
Edit: The reason why I have a post is because if the sign up form has an error, it will redirect back to the sign up page, but this time for some reason the action is no longer new, but create
current_page?
will always return false on POST request.
From documentation:
Let’s say we’re in the http://www.example.com/products action with method POST in case of invalid product.
current_page?(controller: 'product', action: 'index')
# => false
Possible workarounds:
if controller.controller_name == "users" && controller.action_name == "create"
or
if request.path == "/signup"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With