Coherence 0.6.0 introduces a new controller design that splits each controller into 2 files:
Coherence.xxxControllerBase
contains all the functions previously found inCoherence.xxxController
- The new functions are wrapped in a using macro, with one mandatory option. The
schemas
option specifies the name of your projectsSchemas
module. - All functions are overridable
- All private functions have been made public to support overriding
- The new functions are wrapped in a using macro, with one mandatory option. The
Coherence.xxxController
contains only a few lines, as shown by the following example:
defmodule MyAppWeb.Coherence.SessionController do
@moduledoc """
Handle the authentication actions.
Module used for the session controller when the parent project does not
generate controllers. Most of the work is done by the
`Coherence.SessionControllerBase` inclusion.
"""
use CoherenceWeb, :controller
use Coherence.SessionControllerBase, schemas: MyApp.Coherence.Schemas
plug :layout_view, view: Coherence.SessionView, caller: __MODULE__
plug :redirect_logged_in when action in [:new, :create]
end
The following procedure is recommented to upgrade your project:
- BEFORE doing the
mix deps.update coherence
do the following:- run
mix coh.gen.controllers
and overwrite the controllers - run
git diff
and review the customization - save the results of the diff for later reference
- run
- Run
mix deps.update coherence
to upgrade to v0.6.0 (may require changing the vesion inmix.exs
first) - Run
mix coh.install --reinstall
and overwrite desired files - Run
mix coh.gen.controllers
to generate the controllers - Review each contoller that was previously customized and do the following:
- Implement the customized actions in the newly genereated controllers
- Use the base contoller base module as an example. It can be found in
deps/coherence/lib/coherence/controllers/xxx_controller_base.ex