Rails操作被调用两次



正如标题所说,我的操作在单击一次时被触发两次。该操作仅用于复制模型,然后保存复制的模型。

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

我注意到,通过手动输入URL,它可以按预期工作。单击图标运行此操作时,它会打开一个末尾带有#的URL。我不知道这可能是从哪里来的。

正如@max在评论中所说,这可能是涡轮链接的问题,请尝试禁用它以进行类似的操作

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

最新更新