ruby-on-rails – 保留ActiveAdmin布局的ActiveAdmin自定义视图

前端之家收集整理的这篇文章主要介绍了ruby-on-rails – 保留ActiveAdmin布局的ActiveAdmin自定义视图前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个rails 3应用程序与ActiveAdmin宝石.我的目标是使自定义控件在自定义视图中呈现,从而保持布局.

我成功地使用此代码自定义视图中自定义控件渲染:

pages.rb:

ActiveAdmin.register_page 'Pages' do

  content only: :index do
    render 'index'
  end

  content only: :edit do
    render partial: 'edit'
  end

  controller do
    def index
      @search = Page.includes(:translations).where("page_translations.locale='fr'").Metasearch(params[:search])
      @pages = @search.page params[:page]
    end

    def edit
      @page = Page.find params[:id]
    end
  end
end

例如我的index.html.erb文件

<h1>Pages</h1>
<%= form_for @search,:url => admin_pages_path,:html => {:method => :get,:class => "form-inline" } do |f| %>
  <%= f.text_field :translations_name_contains,:class => "search-query input-medium focused" %>
  <%= f.submit("Search",:class => "btn btn-primary") %>
<% end %>

<table>
  <thead>
    <tr>
      <th><%= sort_link @search,:translations_name,"Titre" %></th>
      <th><%= sort_link @search,:permalink,"Permalien" %></th>
      <th>Actions</th>
    </tr>
  </thead>
  <tbody>
    <% @pages.each do |page| %>
      <tr>
        <td><%= page.name %></td>
        <td><%= page.permalink %></td>
        <td><%= link_to("Update",edit_admin_page_path(page)) %></td>
      </tr>
    <% end %>
  </tbody>
</table>

有没有办法保持ActiveAdmin布局?

解决方法

问题解决了.只需在你的代码添加“active_admin”:
controller do
  layout 'active_admin' # <-- here
  def index
    @search = Page.includes(:translations).where("page_translations.locale='fr'").Metasearch(params[:search])
    @pages = @search.page params[:page]
  end

  def edit
    @page = Page.find params[:id]
  end
end
原文链接:https://www.f2er.com/ruby/273105.html

猜你在找的Ruby相关文章