orion icon indicating copy to clipboard operation
orion copied to clipboard

Dynamically get resource's actions

Open juscyllan opened this issue 5 years ago • 0 comments

If I attach a resource without specifying all possible methods, the build fails.

Expected Behavior

  • Throw no errors

Actual Behavior

There was a problem expanding macro 'match'

Code in macro 'match'

 1 | match("/", ->(context : HTTP::Server::Context) { CONTROLLER.new(context).create }, via: "post", helper: false, constraints: nil, format: nil, accept: nil, content_type: nil, type: nil)
     ^
Called macro defined in lib/orion/src/orion/router/routes.cr:276:3

 276 | macro match(path, callable, *, via = :all, helper = nil, constraints = nil, format = nil, accept = nil, content_type = nil, type = nil)

Which expanded to:

 > 4 |   __temp_85 = -> (context : HTTP::Server::Context) {
 > 5 |     ->(context : HTTP::Server::Context) do
 > 6 | (CONTROLLER.new(context)).create
                                 ^-----
Error: undefined method 'create' for Api::Posts

Steps to Reproduce the Problem

require "orion"
require "json"

router Router do
  resources :posts
end

class PostsController < Router::BaseController
  def index
    render text: "Hello world"
  end
end

Router.start

Specifications

  • Version:
  • Platform:
  • Subsystem:

juscyllan avatar Apr 24 '20 02:04 juscyllan