Skip to content

How To: Create a custom view

Jon Crawford edited this page Jan 4, 2019 · 1 revision

Customized view

Let's say we have the following resource: app/admin/articles_admin.rb We want to create a customized index. We are going to create a new folder into `app/views/admin/articles then if we want to edit our file, creating a new file called index.haml (Or the extension which you are using).

  %h4 Number of articles
  %p= @articles.count

In our articles_admin.rb file we define our action called index.

  controller do
    def index
      @articles = Article.where(status: 'published')
    end
  end

Now, let's go to /admin/articles and you'll see the changes.