rubyonjets / jets

Ruby on Jets
http://rubyonjets.com
MIT License
2.6k stars 181 forks source link

Generated routes for a controller are wrong #235

Closed philnash closed 5 years ago

philnash commented 5 years ago

Checklist

Expected Behaviour

I have a Jets app in API mode. I run the controller generator:

jets generate controller Users create

I expect the app to be able to start and to have a new route pointing to the Users controller create action.

Current Behavior

The app fails to start due to an argument error in the routes

Step-by-step reproduction instructions

jets new test-app --mode api
jets generate controller Users create
jets serve

πŸ’₯

bundler: failed to load command: jets (/Users/pnash/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/bin/jets)
ArgumentError: wrong number of arguments (given 1, expected 2)
  /Users/pnash/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/jets-1.8.9/lib/jets/router.rb:27:in `block (2 levels) in <class:Router>'
  /Users/pnash/projects/test-app/config/routes.rb:2:in `block in <top (required)>'
  /Users/pnash/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/jets-1.8.9/lib/jets/router.rb:13:in `instance_eval'
  /Users/pnash/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/jets-1.8.9/lib/jets/router.rb:13:in `draw'
  /Users/pnash/projects/test-app/config/routes.rb:1:in `<top (required)>'
  /Users/pnash/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:291:in `require'
  /Users/pnash/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:291:in `block in require'
  /Users/pnash/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:257:in `load_dependency'
  /Users/pnash/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:291:in `require'
  /Users/pnash/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/jets-1.8.9/lib/jets/application.rb:324:in `load_routes'
  /Users/pnash/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/jets-1.8.9/lib/jets/application.rb:38:in `finish!'
  /Users/pnash/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/jets-1.8.9/lib/jets/booter.rb:21:in `boot!'
  /Users/pnash/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/jets-1.8.9/lib/jets/core.rb:18:in `boot'
  /Users/pnash/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/jets-1.8.9/lib/jets/cli.rb:48:in `boot_jets'
  /Users/pnash/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/jets-1.8.9/lib/jets/cli.rb:20:in `start'
  /Users/pnash/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/jets-1.8.9/lib/jets/cli.rb:5:in `start'
  /Users/pnash/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/jets-1.8.9/exe/jets:14:in `<top (required)>'
  /Users/pnash/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/bin/jets:23:in `load'
  /Users/pnash/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/bin/jets:23:in `<top (required)>`

Code Sample

Jets.application.routes.draw do
  get 'users/create'
  root "jets/public#show"

  # The jets/public#show controller can serve static utf8 content out of the public folder.
  # Note, as part of the deploy process Jets uploads files in the public folder to s3
  # and serves them out of s3 directly. S3 is well suited to serve static assets.
  # More info here: http://rubyonjets.com/docs/assets-serving/
  any "*catchall", to: "jets/public#show"
end

The get 'users/create' is the source of the wrong number of arguments error. It works with:

  get 'users/create', to: 'users#create'

Solution Suggestion

I haven't had time to work on a solution yet. I raised this issue to track it. I will take a look at this tomorrow.

tongueroo commented 5 years ago

It would be awesome if the router was improved so that

  get 'users/create'

Works.

ChrisBr commented 5 years ago

I also tried yesterday

resoures :users, only: [:index]

which also doesn't work. Rails background probably doesn't help πŸ˜„

ChrisBr commented 5 years ago

@tongueroo ^^ is this interface something you would like to support as well?

tongueroo commented 5 years ago

Yes. Want to add resoures: users, only: [:index] Will be part of #308 improvements

tongueroo commented 5 years ago

Done #318 Released in v2.0.0 πŸŽ‰

The get 'users/create' route works now. The controller and action are inferred from the path.