{"id":19929313,"url":"https://github.com/gilcierweb/appelixirphoenix","last_synced_at":"2025-07-04T13:03:43.511Z","repository":{"id":147165661,"uuid":"50241257","full_name":"gilcierweb/appElixirPhoenix","owner":"gilcierweb","description":"Iniciando estudos com Elixir e Phoenix Framework","archived":false,"fork":false,"pushed_at":"2016-01-24T20:21:25.000Z","size":63,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-12T01:14:20.424Z","etag":null,"topics":["elixir","elixir-lang","phoenix","phoenix-framework"],"latest_commit_sha":null,"homepage":null,"language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gilcierweb.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-01-23T14:14:04.000Z","updated_at":"2018-04-25T15:03:42.000Z","dependencies_parsed_at":"2023-04-19T18:16:46.819Z","dependency_job_id":null,"html_url":"https://github.com/gilcierweb/appElixirPhoenix","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gilcierweb%2FappElixirPhoenix","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gilcierweb%2FappElixirPhoenix/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gilcierweb%2FappElixirPhoenix/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gilcierweb%2FappElixirPhoenix/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gilcierweb","download_url":"https://codeload.github.com/gilcierweb/appElixirPhoenix/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241355456,"owners_count":19949365,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["elixir","elixir-lang","phoenix","phoenix-framework"],"created_at":"2024-11-12T22:42:29.821Z","updated_at":"2025-03-01T11:19:20.969Z","avatar_url":"https://github.com/gilcierweb.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"# AppElixirPhoenix\n\nIniciando estudos com Elixir e Phoenix Framework\n\nAutor: GilcierWeb gilcierweb@gmail.com.\n\nWebsite: http://gilcierweb.com.br.\n\nLicença: http://www.opensource.org/licenses/mit-license.php The MIT License.\n\n```shell\ncd AppElixirPhoenix/\n\nmix ecto.create\n\nmix ecto.migrate\n\nmix phoenix.gen.html Post posts title body:text\n```\n\n```rb\n# add web/router.ex\nscope \"/\", AppElixirPhoenix do\n  ...  \n  resources \"/posts\", PostController\nend\n```\n\n```shell\nmix ecto.migrate\n\nmix phoenix.gen.model Comment comments name:string content:text post_id:references:posts\n\nmix ecto.migrate\n\nmix ecto.rollback\n```\n\n```rb\n#add web/models/comment.ex\nbelongs_to :post, AppElixirPhoenix.Post, foreign_key: :post_id\n\n#add web/models/post.ex\nhas_many :comments, AppElixirPhoenix.Comment\n```\n```shell\nmix ecto.migrate\n```\n```rb\n# edit web/router.ex\nresources \"/posts\", PostController do\n  post \"/comment\", PostController, :add_comment\nend\n```\n```shell\nmix phoenix.routes\n\n#result\nGenerated appElixirPhoenix app\n     page_path  GET     /                        AppElixirPhoenix.PageController :index\n     post_path  GET     /posts                   AppElixirPhoenix.PostController :index\n     post_path  GET     /posts/:id/edit          AppElixirPhoenix.PostController :edit\n     post_path  GET     /posts/new               AppElixirPhoenix.PostController :new\n     post_path  GET     /posts/:id               AppElixirPhoenix.PostController :show\n     post_path  POST    /posts                   AppElixirPhoenix.PostController :create\n     post_path  PATCH   /posts/:id               AppElixirPhoenix.PostController :update\n                PUT     /posts/:id               AppElixirPhoenix.PostController :update\n     post_path  DELETE  /posts/:id               AppElixirPhoenix.PostController :delete\npost_post_path  POST    /posts/:post_id/comment  AppElixirPhoenix.PostController :add_comment\n```\n```rb\n#add web/controllers/post_controller.ex\nalias AppElixirPhoenix.Comment\nplug :scrub_params, \"comment\" when action in [:add_comment]\n\ndef add_comment(conn, %{\"comment\" =\u003e comment_params, \"post_id\" =\u003e post_id}) do\n  changeset = Comment.changeset(%Comment{}, Map.put(comment_params, \"post_id\", post_id))\n  post = Post |\u003e Repo.get(post_id) |\u003e Repo.preload([:comments])\n\n  if changeset.valid? do\n    Repo.insert(changeset)\n\n    conn\n    |\u003e put_flash(:info, \"Comment added.\")\n    |\u003e redirect(to: post_path(conn, :show, post))\n  else\n    render(conn, \"show.html\", post: post, changeset: changeset)\n  end\nend\n\ndef show(conn, %{\"id\" =\u003e id}) do\n  post = Repo.get(Post, id) |\u003e Repo.preload([:comments])\n  changeset = Comment.changeset(%Comment{})\n  render(conn, \"show.html\", post: post, changeset: changeset)\nend\n```\n\n```erb\n\u003c%# create file  web/templates/post/comment_form.html.eex %\u003e\n\n\u003c%= form_for @changeset, @action, fn f -\u003e %\u003e\n  \u003c%= if f.errors != [] do %\u003e\n    \u003cdiv class=\"alert alert-danger\"\u003e\n      \u003cp\u003eOops, something went wrong! Please check the errors below:\u003c/p\u003e\n      \u003cul\u003e\n        \u003c%= for {attr, message} \u003c- f.errors do %\u003e\n          \u003cli\u003e\u003c%= humanize(attr) %\u003e \u003c%= message %\u003e\u003c/li\u003e\n        \u003c% end %\u003e\n      \u003c/ul\u003e\n    \u003c/div\u003e\n  \u003c% end %\u003e\n\n  \u003cdiv class=\"form-group\"\u003e\n    \u003clabel\u003eName\u003c/label\u003e\n    \u003c%= text_input f, :name, class: \"form-control\" %\u003e\n  \u003c/div\u003e\n\n  \u003cdiv class=\"form-group\"\u003e\n    \u003clabel\u003eContent\u003c/label\u003e\n    \u003c%= textarea f, :content, class: \"form-control\" %\u003e\n  \u003c/div\u003e\n\n  \u003cdiv class=\"form-group\"\u003e\n    \u003c%= submit \"Add comment\", class: \"btn btn-primary\" %\u003e\n  \u003c/div\u003e\n\u003c% end %\u003e\n\n\u003c%# edit file web/templates/post/show.html.eex %\u003e\n\u003c%= render \"comment_form.html\", post: @post, changeset: @changeset,\naction: post_post_path(@conn, :add_comment, @post) %\u003e\n\n\u003c%= render \"comments.html\", post: @post %\u003e\n\n\u003c%# create file web/templates/post/comments.html.eex%\u003e\n\n\u003ch3\u003e Comments: \u003c/h3\u003e\n\u003ctable class=\"table\"\u003e\n  \u003cthead\u003e\n    \u003ctr\u003e\n      \u003cth\u003e\u003c/th\u003e\n      \u003cth\u003e\u003c/th\u003e\n    \u003c/tr\u003e\n  \u003c/thead\u003e\n  \u003ctbody\u003e\n\u003c%= for comment \u003c- @post.comments do %\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e\u003c%= comment.name %\u003e\u003c/td\u003e\n      \u003ctd\u003e\u003c%= comment.content %\u003e\u003c/td\u003e\n    \u003c/tr\u003e\n\u003c% end %\u003e\n  \u003c/tbody\u003e\n\u003c/table\u003e\n```\n```rb\n#edit web/models/post.ex\n...\nimport Ecto.Query\n...\n\ndef count_comments(query) do\n   from p in query,\n     group_by: p.id,\n     left_join: c in assoc(p, :comments),\n     select: {p, count(c.id)}\nend\n\n#edit web/controllers/post_controller.ex\ndef index(conn, _params) do\n  posts = Post\n  |\u003e Post.count_comments\n  |\u003e Repo.all\n  render(conn, \"index.html\", posts: posts)\nend\n```\n```erb\n\u003c%# edit file web/templates/post/index.html.eex%\u003e\n\u003ch2\u003eListing posts\u003c/h2\u003e\n\n\u003ctable class=\"table\"\u003e\n  \u003cthead\u003e\n    \u003ctr\u003e\n      \u003cth\u003eTitle\u003c/th\u003e\n      \u003cth\u003eBody\u003c/th\u003e\n      \u003cth\u003eCount\u003c/th\u003e\n\n      \u003cth\u003e\u003c/th\u003e\n    \u003c/tr\u003e\n  \u003c/thead\u003e\n  \u003ctbody\u003e\n\u003c%= for {post, count} \u003c- @posts do %\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e\u003c%= post.title %\u003e\u003c/td\u003e\n      \u003ctd\u003e\u003c%= post.body %\u003e\u003c/td\u003e\n      \u003ctd\u003e\u003c%= count %\u003e\u003c/td\u003e\n\n      \u003ctd class=\"text-right\"\u003e\n        \u003c%= link \"Show\", to: post_path(@conn, :show, post), class: \"btn btn-info btn-xs\" %\u003e\n        \u003c%= link \"Edit\", to: post_path(@conn, :edit, post), class: \"btn btn-primary btn-xs\" %\u003e\n        \u003c%= link \"Delete\", to: post_path(@conn, :delete, post), method: :delete, data: [confirm: \"Are you sure?\"], class: \"btn btn-danger btn-xs\" %\u003e\n      \u003c/td\u003e\n    \u003c/tr\u003e\n\u003c% end %\u003e\n  \u003c/tbody\u003e\n\u003c/table\u003e\n\n\u003c%= link \"New post\", to: post_path(@conn, :new), class: \"btn btn-success\" %\u003e\n\n```\n```shell\nmix phoenix.server\n#http://localhost:4000/posts\n```\n\nTo start your Phoenix app:\n\n  1. Install dependencies with `mix deps.get`\n  2. Create and migrate your database with `mix ecto.create \u0026\u0026 mix ecto.migrate`\n  3. Start Phoenix endpoint with `mix phoenix.server`\n\nNow you can visit [`localhost:4000`](http://localhost:4000) from your browser.\n\nReady to run in production? Please [check our deployment guides](http://www.phoenixframework.org/docs/deployment).\n\n## Learn more\n\n  * Official website: http://www.phoenixframework.org/\n  * Guides: http://phoenixframework.org/docs/overview\n  * Docs: http://hexdocs.pm/phoenix\n  * Mailing list: http://groups.google.com/group/phoenix-talk\n  * Source: https://github.com/phoenixframework/phoenix\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgilcierweb%2Fappelixirphoenix","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgilcierweb%2Fappelixirphoenix","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgilcierweb%2Fappelixirphoenix/lists"}