Skip to content

Commit

Permalink
Fix Controller.put_flash and Presence.list arities in docs (#3232)
Browse files Browse the repository at this point in the history
  • Loading branch information
michallepicki authored and Gazler committed Jan 7, 2019
1 parent a893401 commit 1f3f66d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion guides/contexts.md
Expand Up @@ -158,7 +158,7 @@ end

We've seen how controllers work in our [controller guide](controllers.html), so the code probably isn't too surprising. What is worth noticing is how our controller calls into the `Accounts` context. We can see that the `index` action fetches a list of users with `Accounts.list_users/0`, and how users are persisted in the `create` action with `Accounts.create_user/1`. We haven't yet looked at the accounts context, so we don't yet know how user fetching and creation is happening under the hood – *but that's the point*. Our Phoenix controller is the web interface into our greater application. It shouldn't be concerned with the details of how users are fetched from the database or persisted into storage. We only care about telling our application to perform some work for us. This is great because our business logic and storage details are decoupled from the web layer of our application. If we move to a full-text storage engine later for fetching users instead of a SQL query, our controller doesn't need to be changed. Likewise, we can reuse our context code from any other interface in our application, be it a channel, mix task, or long-running process importing CSV data.

In the case of our `create` action, when we successfully create a user, we use `Phoenix.Controller.put_flash/2` to show a success message, and then we redirect to the `user_path`'s show page. Conversely, if `Accounts.create_user/1` fails, we render our `"new.html"` template and pass along the Ecto changeset for the template to lift error messages from.
In the case of our `create` action, when we successfully create a user, we use `Phoenix.Controller.put_flash/3` to show a success message, and then we redirect to the `user_path`'s show page. Conversely, if `Accounts.create_user/1` fails, we render our `"new.html"` template and pass along the Ecto changeset for the template to lift error messages from.

Next, let's dig deeper and check out our `Accounts` context in `lib/hello/accounts/accounts.ex`:

Expand Down
4 changes: 2 additions & 2 deletions lib/phoenix/presence.ex
Expand Up @@ -369,15 +369,15 @@ defmodule Phoenix.Presence do
## Examples
Uses the same data format as `Phoenix.Presence.list/1`, but only
Uses the same data format as `Phoenix.Presence.list/2`, but only
returns metadata for the presences under a topic and key pair. For example,
a user with key `"user1"`, connected to the same chat room `"room:1"` from two
devices, could return:
iex> MyPresence.get_by_key("room:1", "user1")
%{name: "User 1", metas: [%{device: "Desktop"}, %{device: "Mobile"}]}
Like `Phoenix.Presence.list/1`, the presence metadata is passed to the `fetch`
Like `Phoenix.Presence.list/2`, the presence metadata is passed to the `fetch`
callback of your presence module to fetch any additional information.
"""
def get_by_key(module, topic, key) do
Expand Down

0 comments on commit 1f3f66d

Please sign in to comment.