If I create resourceful routes like:
resources "posts", PostController, [:index, :show]
It errors on compile because all the other actions don't exist in my controller. This happens because the if in the following code happens at run time but the macro that creates the route happens at compile time.
macro resources(path, controller, actions = [:index, :edit, :new, :show, :create, :update, :put, :delete])
get "{{path.id}}", {{controller}}, :index if {{actions}}.includes?(:index)
get "{{path.id}}/:id/edit", {{controller}}, :edit if {{actions}}.includes?(:edit)
get "{{path.id}}/new", {{controller}}, :new if {{actions}}.includes?(:new)
get "{{path.id}}/:id", {{controller}}, :show if {{actions}}.includes?(:show)
post "{{path.id}}", {{controller}}, :create if {{actions}}.includes?(:create)
patch "{{path.id}}/:id", {{controller}}, :update if {{actions}}.includes?(:update)
put "{{path.id}}/:id", {{controller}}, :update if {{actions}}.includes?(:update)
delete "{{path.id}}/:id", {{controller}}, :delete if {{actions}}.includes?(:delete)
end
The fix would probably be to check if actions include the right thing at compile time in the macro before creating the route. Like this:
{% if actions.includes?(:index) %}
get "{{path.id}}", {{controller}}, :index
{% end %}
I can send a PR on this unless there's a specific reason the code is written that way.