This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule EctoSlugs.Blog.Article.TitleSlug do | |
use EctoAutoslugField.Slug, to: :slug | |
import Ecto.Changeset | |
def get_sources(changeset, _opts) do | |
# This function is used to get sources to build slug from: | |
base_fields = [:title] | |
if get_change(changeset, :breaking, false) do |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule EctoSlugs.Blog.Article.TitleSlug do | |
use EctoAutoslugField.Slug, from: :title, to: :slug | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule EctoSlugs.Repo.Migrations.CreateEctoSlugs.Blog.Article do | |
use Ecto.Migration | |
def change do | |
alter table(:blog_articles) do | |
add :slug, :string | |
end | |
create unique_index(:blog_articles, [:slug]) # should be unique | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule EctoSlugs.Blog.Article do | |
use Ecto.Schema | |
import Ecto.Changeset | |
alias EctoSlugs.Blog.Article | |
alias EctoSlugs.Blog.Article.TitleSlug | |
schema "blog_articles" do | |
field :breaking, :boolean, default: false | |
field :content, :string | |
field :title, :string |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule EctoSlugs.Blog.Article do | |
use Ecto.Schema | |
import Ecto.Changeset | |
alias EctoSlugs.Blog.Article | |
schema "blog_articles" do | |
field :breaking, :boolean, default: false | |
field :content, :string | |
field :title, :string |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- Logging error --- | |
Traceback (most recent call last): | |
File "/Users/sobolev/.virtualenvs/bre_slots_rest/lib/python3.6/site-packages/django/template/base.py", line 885, in _resolve_lookup | |
current = current[bit] | |
TypeError: list indices must be integers or slices, not str | |
During handling of the above exception, another exception occurred: | |
Traceback (most recent call last): | |
File "/Users/sobolev/.virtualenvs/bre_slots_rest/lib/python3.6/site-packages/django/template/base.py", line 893, in _resolve_lookup |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule MediumPhxExample.Web.FallbackController do | |
@moduledoc """ | |
Translates controller action results into valid `Plug.Conn` responses. | |
See `Phoenix.Controller.action_fallback/1` for more details. | |
""" | |
use MediumPhxExample.Web, :controller | |
def call(conn, {:error, %Ecto.Changeset{} = changeset}) do | |
conn |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule MediumPhxExample.Web.AlbumController do | |
use MediumPhxExample.Web, :controller | |
alias MediumPhxExample.Audio | |
alias MediumPhxExample.Audio.Album | |
action_fallback MediumPhxExample.Web.FallbackController | |
# ... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Example.UserController do | |
use Example.Web, :controller | |
# ... | |
def update(conn, %{"id" => id, "user" => user_params}) do | |
user = Repo.get!(User, id) | |
changeset = User.changeset(user, user_params) | |
case Repo.update(changeset) do |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule MediumPhxExample.Audio do | |
@moduledoc """ | |
The boundary for the Audio system. | |
""" | |
import Ecto.{Query, Changeset}, warn: false | |
alias MediumPhxExample.Repo | |
alias MediumPhxExample.Audio.Album |