Open sureshprasanna70 opened 6 years ago
@sureshprasanna70 can you post the rest of your example code so I can run it to track down the issue?
@jakehow I'm sorry. This is the grape api
module Users
class InviteAPI < Grape::API
resources :invite do
params do
requires :invitation, type: Hash do
requires :email, type: String, allow_blank: false, desc: "Invitee Email"
requires :first_name, type: String, allow_blank: false, desc: "Invitee First Name"
requires :last_name, type: String, allow_blank: true, desc: "Invitee Last Name"
end
end
post "send" do
authenticate_user!
email = params[:invitation][:email]
first_name = params[:invitation][:first_name]
last_name = params[:invitation][:last_name]
@invite = Invitation.new(:first_name => first_name,:last_name => last_name,:email => email,:user_id => current_user.id)
if @invite.save
return true
else
invitation_failed_error
end
end
end
helpers do
def invitation_failed_error
throw_errors(422, "Invitation failed")
end
end
end
end
Hope this helps.
@sureshprasanna70 can you put the whole thing up as a repo or a gist? I don't use grape so don't know what the Gemfile should look like, etc. Looks like you have an Invitation
model also.
I'm sorry and can't do that. The code is protected and can't be shared publicly. The invitation model contains the fields like first_name
,last_name
, email
and user_id
. The gemfile is
source 'https://rubygems.org'
ruby '2.4.0'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.8'
# Postgres for database
gem 'pg', '0.20.0'
# Grape is a REST-like API micro-framework for Ruby
gem 'grape', '0.19.2'
# Use Rabl templates in Grape
gem 'grape-rabl', '0.4.2'
# Use Devise for authendication and authorization
gem 'devise', '4.2.1'
# For communicating with the Twilio API
gem 'twilio-ruby', '~> 4.11.1'
# Cross domain access
gem 'rack-cors', '0.4.1', :require => 'rack/cors'
# Use Puma as the app server
gem 'puma', '3.8.2'
#Abort requests that are taking too long; an exception is raised.
gem 'rack-timeout', '0.4.2'
group :production, :test do
# SendGrid - To send transactional emails
gem 'sendgrid-ruby', '5.2.0'
end
group :development do
# Access an IRB console on exception pages or by using <%= console %> in views
gem 'web-console', '~> 2.0'
# Web interface for emails
gem 'mailcatcher'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring', '2.0.1'
end
group :development, :test do
# For generating fake data
gem 'faker', '1.7.3'
# Add a comment summarizing the current schema
gem 'annotate', '2.7.2'
#For testing
gem 'rspec-rails', '~> 3.7'
gem 'rspec_api_documentation'
end
The formatter used is
api_blueprint
. The generated docs misses the scope for parameters. Other writers likehtml
,json
andmarkdown
works good. Butapi_blueprint
misses the scope key This is my specGenerated docs