Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ActiveAdmin custom views which retain the ActiveAdmin layout

I have a rails 3 app with the ActiveAdmin gem. My goal is to make a custom controller rendering in custom views which keep it layout.

I succeeded to make a custom controller rendering in custom views with this code :

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

And for example my index.html.erb file :

<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>

Is there a means to keep the ActiveAdmin layout ?

like image 883
Jérémy Pouyet Avatar asked Sep 24 '13 09:09

Jérémy Pouyet


2 Answers

Problem solved. Just add layout 'active_admin' to your code :

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
like image 199
Jérémy Pouyet Avatar answered Nov 12 '22 21:11

Jérémy Pouyet


code is here : for model less view with admin layout

  ActiveAdmin.register_page "myname" do

  content only: :index do
    render 'index'
  end

  controller do
     def index
     end
  end
end

Then add views under app/views/admin/myname/ as _index.html.erb

like image 26
errakeshpd Avatar answered Nov 12 '22 19:11

errakeshpd