Creating a Phoenix Framework Application with SQLite

Phoenix defaults to using Postgres, which is probably very sensible. Getting SQLite up and running using Sqlite.Ecto, though, is pretty trivial and requires a couple of config tweaks.

First, add the dependency for sqlite_ecto in mix.exs:

defp deps do
  [...
   {:sqlite_ecto, "~> 1.0.0"},
   ...]
end

Now update your config/dev.exs to include reference Sqlite.Ecto:

config :widgetapp, Widgetapp.Repo,
  adapter: Sqlite.Ecto,
  database: "path/to/widgetapp.sqlite"

Drop into your console and run mix deps.get to pull in your new dependencies and then run mix ecto.create to get your database set up. If all goes well, you should get a new file created as specified in your dev.exs as above.

From here, just develop as normal.

Rendering partials from other view modules in Phoenix

Playing with Elixir and Phoenix at the moment, so here is a small snippet.

When you want to render a partial template that sits in a different view module, here’s the syntax:

<%= render ApplicationName.ViewModule, viewname, conn: @conn %>

So, for example, if we have the following application structure:

web
 - controllers
   - about_controller.ex
   - page_controller.ex
 - templates
   - about
     - index.html.eex
   - page
     - index.html.eex
 - views
   - about_view.ex
   - page_view.ex

And we want to include the `about/index` page on our `page/index`, we can do the following somewhere in our `index.html.eex`:

<%= render Myapp.AboutView, "indexhtml", conn: @conn %>