Last active
August 29, 2015 14:23
-
-
Save darui00kara/456cbda48e59611c28fc to your computer and use it in GitHub Desktop.
This file contains hidden or 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 PhoenixBbs.BbsController do | |
| use PhoenixBbs.Web, :controller | |
| plug :action | |
| def index(conn, _params) do | |
| docs = Mongo.connect! | |
| |> Mongo.db("phoenix_bbs") | |
| |> Mongo.Db.collection("comments") | |
| |> Mongo.Collection.find | |
| |> Enum.to_list | |
| render conn, "bbs.html", comments: docs | |
| end | |
| def create(conn, params) do | |
| collection = Mongo.connect! |> Mongo.db("phoenix_bbs") |> Mongo.Db.collection("comments") | |
| %{name: params["name"], | |
| title: params["title"], | |
| comment: params["comment"] | |
| } |> Mongo.Collection.insert_one!(collection) | |
| redirect conn, to: "/bbs" | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment