Skip to content

Commit

Permalink
Adding instructions for getting started with API-only apps (#1008)
Browse files Browse the repository at this point in the history
* Link to instructions for API-only app
* Add note about root route in Getting Started
* Adding additional notes for setup for API-only apps
* Editing note that links to guide
  • Loading branch information
oyeanuj authored and nickcharlton committed Oct 18, 2017
1 parent 8aa9018 commit 3366bd1
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ $ rails generate administrate:install
Restart your server, and visit http://localhost:3000/admin
to see your new dashboard in action.

For more detailed instructions or to make it work with Rails API-only applications, please go through the ['Getting Started` guide](https://administrate-prototype.herokuapp.com/getting_started).


## Create Additional Dashboards

In order to create additional dashboards, pass in the resource name to
Expand Down
41 changes: 40 additions & 1 deletion docs/getting_started.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,20 @@ The `Admin::ApplicationController` can be customized to add
authentication logic, authorization, pagination,
or other controller-level concerns.

You will also want to add a `root` route to show a dashboard when you go to `/admin`.

```ruby
Rails.application.routes.draw do
namespace :admin do
# Add dashboard for your models here
resources :customers,
resources :orders

root to: "customers#index" # <--- Root route
end
end
```

The routes can be customized to show or hide
different models on the dashboard.

Expand Down Expand Up @@ -62,7 +76,9 @@ end
## Rails API

Since Rails 5.0, we've been able to have API only applications. Yet, sometimes
we still want to have an admin. To get this working, please update this config:
we still want to have an admin.

To get this working, we recommend updating this config:

```ruby
# config/application.rb
Expand All @@ -74,3 +90,26 @@ also don't use your `ApplicationController`. Instead, Administrate provides its
own. Meaning you're free to specify `ActionController::API` as your parent
controller to make sure no flash, session, or cookie middleware is used by your
API.

Alternatively, if your application needs to have `config.api_only = true`, we recommend you add the following lines to your `config/application.rb`

```ruby
# Enable Flash, Cookies, MethodOverride for Administrate Gem
config.middleware.use ActionDispatch::Flash
config.session_store :cookie_store
config.middleware.use ActionDispatch::Cookies
config.middleware.use ActionDispatch::Session::CookieStore, config.session_options
config.middleware.use ::Rack::MethodOverride
```

You must also ensure that the all the required controller actions are available and accessible as routes since generators in API-only applications only generate some of the required actions. Here is an example:

```ruby
# routes.rb
namespace :admin do
resources name, only: %i(index show new create edit update destroy)
end

# names_controller.rb
# Ensure each of those methods are defined
```

0 comments on commit 3366bd1

Please sign in to comment.