Я использовал виноград и чванство для бэкэнда Rails - приложение API Rails 6
Я использовал следующие драгоценные камни для
gem 'grape'
gem 'grape-swagger'
gem 'grape-swagger-rails'
gem 'grape-jbuilder'
Я создал один контроллер UserLocations
module API
module V1
class UserLocations < API::V1::Base
include API::Defaults
resource :user_locations do
desc 'Get User Locations',
headers: {
'Authorization' => { description: 'Authorization Header', required: true },
'Access-Token' => { description: 'Access Token', required: true }
}
params do
optional :filter, type: JSON, desc: 'Filter object' do
optional :gender, type: String, desc: 'Male/Female'
optional :user_type, type: String, desc: 'User Type Guest/Registered'
end
end
get '/', jbuilder: 'user_locations/user_locations.json.jbuilder' do
authenticate!
binding.pry
if params[:user_locations_ids].present?
@users_locations = UserLocation.where(id: params[:user_locations_ids].map(&:to_i))
return
end
@user_locations = UserLocation.includes(user: [:user_profile, :verification, car_detail: [:brand]])
.select("user_profiles.username, user_profiles.gender, user_profiles.dob, user_profiles.user_type,
verifications.status, brands.name, user_locations.location_time, user_locations.city,
user_locations.state, user_locations.country, user_locations.postcode, user_locations.road")
.references(user: [:user_profile, :verification, car_detail: [:brand]])
end
end
end
end
end end
Я создал файл user_locations. json .builder в папке user_locations в представлении
Мой файл routes.rb
Rails.application.routes.draw do
mount API::Base => '/api'
mount GrapeSwaggerRails::Engine => '/swagger'
end
Я получаю следующую ошибку:
ActionController::RoutingError (No route matches [GET] "/api/v1/user_locations"):