I'm trying to create a basic rails app. I created an apis controller like so
class ApisController < ApplicationController
def calendar
#code
render json: @response
end
end
and my routing file looks like this
namespace :api, defaults: {format: 'json'} do
get 'calendar' => 'apis#calendar'
end
Unfortunately i get the error uninitialized constant Api
. I would ideally like to keep the api as simple as possible. Where am I going wrong
Any help is appreciated and Merry Christmas!
I recommend wrapping it in a module. You can manage versioning the same way.
Here's an example:
https://www.amberbit.com/blog/2014/2/19/building-and-documenting-api-in-rails/
Figured using scopes instead of namespaces
scope :api, defaults: {format: 'json'} do
get 'calendar' => 'apis#calendar'
end
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.