a little background story :
i want to put devise sign-in form on show method of my controller. it goes something like this
app/views/projects/show.html.erb
<p><%= @project.name %> </p>
<p><%= @project.description %> </p>
<% if user_signed_in? %>
// show link to download files
<% else >
<p> please login to view files </p>
// show devise signin form
<% end %>
and i want the user redirect to this current page (show view) whether sign-in are success or failed.
To address failed signin redirect - i've set custom_failure.rb in lib directory, set Devise initializer, and rails config.autoload_paths.
class CustomFailure < Devise::FailureApp
def redirect_url
url = Rails.application.routes.recognize_path(request.referer)
if url[:controller] == "projects" && url[:action] == "show"
stored_location_for(resource)
else
super
end
end
def respond
if http_auth?
http_auth
else
redirect
end
end
end
my question is i do not want to use request.referer in this line in custom_failure.rb.
url = Rails.application.routes.recognize_path(request.referer)
since people says request.referer its not stable.
any ideas?
edit : actually my question is very similiar to this post here. in that post he wanted to redirect to site#index if sign in failed, while i want to redirect to current page if sign_in fails. rails (5.1.2) devise (4.4.1)