[英]Rails action being called twice
As the title says, my action is being fired twice when clicked a single time.正如标题所说,单击一次时,我的动作被触发了两次。 The action is just meant for copying a model then saving the copied model.
该操作仅用于复制 model 然后保存复制的 model。
module RailsAdmin
module Config
module Actions
class CopyAction < RailsAdmin::Config::Actions::Base
RailsAdmin::Config::Actions.register(self)
register_instance_option :member do
true
end
register_instance_option :http_methods do
[:get]
end
register_instance_option :controller do
proc do
if request.get? # EDIT
@newObject = @object.dup
objectNameCopy = @object.name + "_copy_"
@queues = Filter.where('name LIKE ?',"%#{objectNameCopy}%")
x = 1
@queues.each do |q|
x=x+1
end
@newObject.name = @newObject.name + "_copy_" + x.to_s
@newObject.key = @newObject.key + "_copy_" + x.to_s
if @newObject.save!
respond_to do |format|
format.html { redirect_to_on_success }
end
else
@newObject.errors.full_messages.each do |message|
flash.now[:error] = message
end
end
end
end
end
register_instance_option :link_icon do
'fa fa-copy'
end
end
end
end
end
I have noticed that by entering the URL manually, it works as intended.我注意到通过手动输入 URL ,它可以按预期工作。 When clicking the icon to run this action, it opens a URL with a
#
at the end.单击图标运行此操作时,它会打开一个 URL,末尾带有
#
。 I've not a clue where this could be coming from.我不知道这可能来自哪里。
As a @max said in the comments its probably a turbolinks issue, try disabling it for your action like this正如@max 在评论中所说,它可能是一个 turbolinks 问题,请尝试为您的操作禁用它
module RailsAdmin
module Config
module Actions
class CopyAction < RailsAdmin::Config::Actions::Base
RailsAdmin::Config::Actions.register(self)
# ADD THIS
register_instance_option :pjax? do
false
end
end
end
end
end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.