-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixing back Redirectable #381
Conversation
redirect_to redirect, notice: "#{resource.model_name.human} was successfully updated." | ||
end | ||
end | ||
update! { params[:return_to] || collection_path } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This won't return to the previous page on failure?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This shortcut is described here https://github.com/activeadmin/inherited_resources#overwriting-actions
if block.present? | ||
extended = Proc.new do |f| | ||
return_to = request.params[:return_to] || request.referer | ||
f.hidden_field :return_to, name: :return_to, value: return_to if return_to.present? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't it be also disabled so that it's not sent in the form params?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this must be sent back to controller (saved between requests) via params in this case. Otherwise, it won't work after validation errors. That's why I first check params[:return_to]
if there is a value.
It should be sent with forms params, that the trick to save it between
validation errored requests. As for redirect shortcut I took it from
inherited resources documentation so it should be good.
…On Thu, Dec 22, 2022, 20:58 Tiago Santos ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In app/controllers/concerns/back_redirectable.rb
<#381 (comment)>:
>
+ def form(options = {}, &block)
+ if block.present?
+ extended = Proc.new do |f|
+ return_to = request.params[:return_to] || request.referer
+ f.hidden_field :return_to, name: :return_to, value: return_to if return_to.present?
shouldn't it be also disabled so that it's not sent in the form params?
—
Reply to this email directly, view it on GitHub
<#381 (review)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAJ2CLCQ3W5EUGPP73H6RHLWOSXGNANCNFSM6AAAAAAS4JV5DE>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
super | ||
end | ||
|
||
def self.extended(base) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this gets evaluated just by extending the module?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure I understood it well :P
Yeah, first time I use that to be honest.
…On Thu, Dec 22, 2022, 21:02 Tiago Santos ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In app/controllers/concerns/back_redirectable.rb
<#381 (comment)>:
> @@ -1,36 +1,28 @@
# frozen_string_literal: true
module BackRedirectable
- def back_redirect
- controller do
- def edit
- session[:return_to] ||= request.referer
- super
- end
-
- def new
- session[:return_to] ||= request.referer
- super
- end
-
+ def self.extended(base)
this gets evaluated just by extending the module?
—
Reply to this email directly, view it on GitHub
<#381 (review)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAJ2CLDXM7PYT3BJH2L3OOTWOSXUNANCNFSM6AAAAAAS4JV5DE>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Sorry looks like responding via email is not great as it responds to main thread. |
Little hacky, but looks like it works.
Story: https://www.pivotaltracker.com/story/show/183760908