json - Deploying a Rails API on either Heroku/AWS Elastic Beanstalk -


i'm trying pair mobile client rest api json data can display in app. i'm following apis on rails abraham kuri vargas. in api have created subdomain versioning, controller files in app/controllers/api/v1. api returns desired json data when run locally. problem i'm facing whenever deploy api onto heroku/aws show "application not found". remote server isn't finding way app/controllers/api/v1? there fix problem because in book author has written "due structure of application not going deploy app server". i'm stuck on problem long time , love suggestions!

app/controllers/api/v1/users_controller.rb

    class api::v1::userscontroller < applicationcontroller      respond_to :json       def show       respond_with user.find(params[:id])      end       def create      user = user.new(user_params)       if user.save        render json: user, status: 201, location: [ :api,user ]       else        render json: { errors: user.errors }, status: 422       end      end       def update      user = user.find(params[:id])       if user.update(user_params)        render json: user, status: 200, location: [ :api,user ]       else        render json: { errors: user.errors }, status: 422       end      end       def destroy       user = user.find(params[:id])       user.destroy       head 204      end       private       def user_params        params.require(:user).permit(:email,:password,:password_confirmation)       end     end 

config/routes.rb

    require 'api_constraints'      rails.application.routes.draw        devise_for :users       namespace :api, defaults: { format: :json }, constraints: { subdomain: 'api' }, path: '/'          scope module: :v1, constraints: apiconstraints.new(version: 1, default: true)           #resources            resources :users, :only => [:show, :create, :update, :destroy]         end        end     end 

output, when run localhosts://3000/users/1 locally

{"id":1,"email":"example@marketplace.com","created_at":"2016-06-09t05:36:06.606z","updated_at":"2016-06-09t05:36:06.606z"}

heroku server logs when run petoye.herokuapp.com/users/1

started "/users/1" 120.60.22.244 @ 2016-06-12 06:43:36 +0000
actioncontroller::routingerror (no route matches [get] "/users/1"):
vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.6/lib/action_dispatch/middleware/debug_exceptions.rb:21:in call'
vendor/bundle/ruby/2.2.0/gems/railties-4.2.6/lib/rails/rack/logger.rb:38:in
call_app'
vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.6/lib/active_support/tagged_logging.rb:68:in block in tagged'
vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.6/lib/active_support/tagged_logging.rb:68:in
tagged' vendor/bundle/ruby/2.2.0/gems/railties-4.2.6/lib/rails/rack/logger.rb:20:in call'
vendor/bundle/ruby/2.2.0/gems/rack-1.6.4/lib/rack/methodoverride.rb:22:in
call'
vendor/bundle/ruby/2.2.0/gems/rack-1.6.4/lib/rack/runtime.rb:18:in call'
2016-06-12t06:43:36.946702+00:00 app[web.1]: vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.6/lib/active_support/cache/strategy/local_cache_middleware.rb:28:in
call'
vendor/bundle/ruby/2.2.0/gems/puma-3.4.0/lib/puma/server.rb:569:in handle_request'
vendor/bundle/ruby/2.2.0/gems/puma-3.4.0/lib/puma/thread_pool.rb:114:in
block in spawn_thread'

steps on how configure heroku rails api

  1. first need buy domain using registrar, buy www.example.com, can use subdomain api.example.com. once that's done need tell heroku listen requests @ api.example.com. can done typing on cmd

    heroku domains:add api.example.com 
  2. after using domains:add command must point dns provider @ domain’s dns target supplied heroku. done creating cname entry example.herokuapp.com (type heroku info name of app). above process made simple if use service dnsimple (https://www.youtube.com/watch?v=rr6jy9i0cws). add cname record of api.example.com points example.herokuapp.com

  3. one important thing forgets once deploy heroku run heroku run rake db:migrate command.

once done able access api using api.example.com/any_endpoints

additional resources: https://devcenter.heroku.com/articles/custom-domains https://support.dnsimple.com/articles/alias-record/


Comments

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -