在 ActiveAdmin 的“自定义页面”中呈现自定义编辑部分

And*_*res 3 ruby-on-rails activeadmin

我正在为一个项目使用 ActiveAdmin。我有并且我有一个自定义表单的部分。当用户单击按钮时,我希望能够呈现这个自定义表单,所以这就是我所做的:

 ActiveAdmin.register_page "Messages" do

    menu priority: 5
    welcome_message = Template.first

    page_action :update, method: :put do
      #update code
    end

    page_action :edit, :method => :get do
      render partial:'custom_form', locals: { settings: welcome_message }
    end

    action_item do
      link_to "Edit", admin_welcome_messages_edit_path, :method => :get
    end

    content do
      render text: "HI"
    end
  end
Run Code Online (Sandbox Code Playgroud)

这有效,但问题是我的表单在没有 ActiveAdmin 的布局和样式的情况下呈现,它只是将我的显示custom_form为干净的 html。

如果我使我custom_formcontent do ... end它的工作,但我需要表现出不同的东西。

有什么帮助吗??我不知道还能尝试什么,我已经到达了 google 的前 3 页,但没有成功!!

And*_*res 5

我没有找到这个问题的答案,但我找到了一个看起来不错的解决方法。

action_item我有一个链接到admin_welcome_messages_path主视图,如果我正在编辑,请在其中添加一个参数以显示表单而不是正文。

希望它对某人有帮助!

  ActiveAdmin.register_page "Messages" do

    menu priority: 5
    welcome_message = Template.first

    page_action :update, method: :put do
      #update code
    end

    action_item do
      link_to "Edit", admin_welcome_messages_path(edit: true), :method => :get
    end

    content do
      if params["edit"] == "true"
        render partial:'form', locals: { settings: welcome_message }  
      else
        render partial:'body'
      end
    end
  end
Run Code Online (Sandbox Code Playgroud)


小智 5

有点老问题,但我遇到了同样的问题,这为我解决了。

render partial: "name_of_your_partial", layout: "active_admin" 
Run Code Online (Sandbox Code Playgroud)

也不适合我,所以我只是将我的部分更改为模板。

render: "name_of_your_template", layout: "active_admin"
Run Code Online (Sandbox Code Playgroud)

现在正在显示 activeadmin 布局。

  • 当我尝试“渲染:“name_of_your_template”,布局:“active_admin”时遇到语法错误,我必须在渲染后删除冒号,如下所示:“渲染“name_of_your_template”,布局:“active_admin”` (2认同)