Creating an API with Rails, Doorkeeper, and Grape
<!-- app/views/shared/_messages.html.erb --> | |
<% unless flash.empty? %> | |
<div id='flash-messages'> | |
<% flash.each do |name, message| %> | |
<div class="flash alert-box <%= flash_class(name) %>" data-alert=''> | |
<%= message %> | |
<a href='#' class='close'>×</a> | |
</div> | |
<% end %> | |
</div> | |
<% end %> |
<!-- app/views/layouts/application.html.erb --> | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>ApiSample</title> | |
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %> | |
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %> | |
<%= csrf_meta_tags %> | |
</head> | |
<body> | |
<%= render 'shared/messages' %> | |
<%= yield %> | |
</body> | |
</html> |
# app/helpers/application_helper.rb | |
module ApplicationHelper | |
def flash_class(key) | |
case key | |
when 'notice' then 'info' | |
when 'success' then 'success' | |
when 'alert' then 'warning' | |
when 'error' then 'alert' | |
end | |
end | |
end |
# config/environments/development.rb | |
Rails.application.configure do | |
# Settings specified here will take precedence over those in config/application.rb. | |
# Ommited for brevity | |
config.action_mailer.default_url_options = { host: 'localhost', port: 3000 } | |
end |
$ rails generate devise:install |
$ rails generate devise user | |
$ rake db:migrate |
source 'https://rubygems.org' | |
gem 'rails', '4.1.6' | |
gem 'sqlite3' | |
gem 'sass-rails', '~> 4.0.3' | |
gem 'uglifier', '>= 1.3.0' | |
gem 'coffee-rails', '~> 4.0.0' | |
gem 'jquery-rails' | |
gem 'turbolinks' | |
gem 'jbuilder', '~> 2.0' | |
gem 'sdoc', '~> 0.4.0', group: :doc | |
gem 'spring', group: :development | |
# Gems we're going to use | |
gem 'devise' | |
gem 'doorkeeper' | |
gem 'grape' |
# app/controllers/home_controller.rb | |
class HomeController < ApplicationController | |
def index | |
end | |
end |
<!-- app/views/home/index.html.erb --> | |
<h1>Welcome!</h1> |
$ rails new api |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment