Few day ago, I started using Phoenix 1.3, and everything was fine until I started adding a new action in the controller.
Router.ex
resources "/users", UserController, only: [:show] do
resources "/events", EventController do
get "/:id", EventController, :join, as: :join
end
end
Event_controller.ex
def join(conn, %{"event_id" => id}, current_user) do
#some stuff..
conn
|> put_status(:ok)
|> put_flash(:info, "You just joined Event")
|> redirect(to: page_path(conn, :index, current_user))
end
then in my show template: /event/show.html.eex
<%= link "To list", to: user_event_path(@conn, :index, @event.user) %>
<%= if @current_user.id != @user.id do %>
<h1> <%= @user.name %> Event ! </h1>
<h3> <%= @event.title %></h3>
<p><%= @event.description %></p>
<p><%= @event.location %></p>
<p><%= @event.price %></p>
<%= link "Join", to: user_event_path(@conn, :join, @current_user.id,
@event.id), class: "btn btn-default btn-xs" %>
I tried to do something like that in other projects with Phoenix 1.2 and its work, but it wasn't exactly the same code.
Can someone help me to understand why it is not working...
Btw sorry for my English!
The Error saying :
No function clause for Eventoma.Web.Router.Helpers.user_event_path/4
and action :join. The following actions/clauses are supported:
user_event_path(conn_or_endpoint, :create, user_id, opts \\ [])
user_event_path(conn_or_endpoint, :delete, user_id, id, opts \\ [])
user_event_path(conn_or_endpoint, :edit, user_id, id, opts \\ [])
user_event_path(conn_or_endpoint, :index, user_id, opts \\ [])
user_event_path(conn_or_endpoint, :new, user_id, opts \\ [])
user_event_path(conn_or_endpoint, :show, user_id, id, opts \\ [])
user_event_path(conn_or_endpoint, :update, user_id, id, opts \\ [])
(phoenix) lib/phoenix/router/helpers.ex:299: Phoenix.Router.Helpers.raise_route_error/5