 
   alias EspiDni.NotificationMessage
 
+  use Plug.ErrorHandler
+  plug :scrub_params, "notification_message" when action in [:create, :update]
+
   def index(conn, _params) do
     notification_messages = Repo.all(NotificationMessage)
-    render(conn, "index.html", notification_messages: notification_messages)
+    render(conn, "index.html", notification_messages: user_messages(conn))
   end
 
   def new(conn, _params) do

  end

  def create(conn, %{"notification_message" => notification_message_params}) do
    changeset = NotificationMessage.changeset(%NotificationMessage{}, notification_message_params)

    case Repo.insert(changeset) do
      {:ok, _notification_message} ->

  end

  def show(conn, %{"id" => id}) do
    notification_message = get_user_message(conn, id)
    render(conn, "show.html", notification_message: notification_message)
  end

  def edit(conn, %{"id" => id}) do
    notification_message = get_user_message(conn, id)
    changeset = NotificationMessage.changeset(notification_message)
    render(conn, "edit.html", notification_message: notification_message, changeset: changeset)
  end

  def update(conn, %{"id" => id, "notification_message" => notification_message_params}) do
    notification_message = get_user_message(conn, id)
    changeset = NotificationMessage.changeset(notification_message, notification_message_params)

    case Repo.update(changeset) do
      {:ok, notification_message} ->
        conn
        |> put_flash(:info, "Notification message updated successfully.")
        |> redirect(to: notification_message_path(conn, :index))
      {:error, changeset} ->
        render(conn, "edit.html", notification_message: notification_message, changeset: changeset)
    end
  end

  def delete(conn, %{"id" => id}) do
    notification_message = get_user_message(conn, id)

    # Here we use delete! (with a bang) because we expect
    # it to always work (and if it does not, it will raise).
