Created
June 28, 2015 14:13
-
-
Save stochastic-thread/09dc3687e187ba64240c to your computer and use it in GitHub Desktop.
Messing with helpers
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 Trophus.Helpers do | |
alias Trophus.Repo | |
alias Trophus.User | |
def current_order(conn) do | |
current_user_id = conn.private.plug_session["current_user"] | |
current_user = Repo.get(User, current_user_id) | |
order_id = get_session(conn, :order_id) | |
if (order_id != nil) do | |
Repo.get(Order, order_id) | |
else | |
# change to changeset, this is wrong | |
# Order.new(%{buyer_id: current_user.id}) | |
end | |
end | |
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 Trophus.PageController do | |
use Trophus.Web, :controller | |
use Trophus.Helpers | |
plug :action | |
def index(conn, _params) do | |
IO.puts "Hello users" | |
url = Instagram.start | |
currord = Helpers.current_order(conn) | |
render conn, "index.html", url: url, current_order: currord | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment