 
   def destroy(conn, defn, params) do
     model = defn.__struct__
-    resource_model = model.__struct__.resource_model
-    |> base_name |> String.downcase |> String.to_atom
+    resource_model = defn.resource_model |> base_name |> String.downcase |> String.to_atom
 
     resource = model.run_query(repo, defn, :edit, params[:id])
 


  def create(conn, defn, params) do
    model = defn.__struct__
    resource = model.__struct__.resource_model.__struct__
    resource_model = model.__struct__.resource_model
    |> base_name |> String.downcase |> String.to_atom
    changeset_fn = Keyword.get(defn.changesets, :create, &resource.__struct__.changeset/2)
    changeset = ExAdmin.Repo.changeset(changeset_fn, resource, params[resource_model])



  def new(conn, defn, params) do
    model = defn.__struct__
    resource = defn.resource_model.__struct__
    contents = do_form_view(model, conn, resource, params)

    render conn, "admin.html", html: contents, resource: resource, filters: nil, defn: defn
