Reputation: 1711
I tried to deploy my new rails app to heroku using mongolab (Only rails framework)
$ rails new myapp --skip-active-record
$ cd myapp
b. Add gems to Gemfile
ruby '2.2.0'
gem 'mongoid', '~> 4', github: 'mongoid/mongoid'
gem 'bson_ext'
group :production do
gem 'rails_12factor'
end
c. bundle those gems and generate mongoid.yml
$ bundle install
$ rails g mongoid:config
d. config mongoid.yml add/modify production to use mongolab
mongoid.yml
production:
sessions:
default:
uri: <%= ENV['MONGOLAB_URI'] %>
e. Create git and heroku apps
$ git init
$ git add .
$ git commit -am 'Initial Commit'
$ heroku login
$ heroku apps:create myapp
f. Addons mongolab
$ heroku addons:add mongolab
And mongolab sandbox display:
mongolab sandbox:
To connect using the shell:
mongo ds051831.mongolab.com:51831/heroku_app34606139 -u <dbuser> -p <dbpassword>
To connect using a driver via the standard URI (what's this?):
mongodb://<dbuser>:<dbpassword>@ds051831.mongolab.com:51831/heroku_app34606139
g. Config my addon credential
$ heroku config | grep MONGOLAB_URI
MONGOLAB_URI: mongodb://heroku_app34655737:[email protected]:51831/heroku_app34655737
Then copy from mongodb://......
$ heroku config:add MONGOLAB_URI=mongodb://my_mongolab_user:[email protected]:51831/heroku_app34606139
h. Deploy myapp to heroku
$ git push heroku master
i. Run myapp on heroku
$ heroku open
The app shown in localhost:3000 ok. But not heroku
Here responsed from heroku screen.
This is heroku logs: at this step
$ heroku logs --tail
2015-03-06T09:26:48.095677+00:00 heroku[web.1]: Process exited with status 143
2015-03-06T09:26:50.640199+00:00 app[web.1]: [2015-03-06 09:26:50] INFO WEBrick 1.3.1
2015-03-06T09:26:50.640660+00:00 app[web.1]: [2015-03-06 09:26:50] INFO WEBrick::HTTPServer#start: pid=3 port=22998
2015-03-06T09:26:50.640225+00:00 app[web.1]: [2015-03-06 09:26:50] INFO ruby 2.0.0 (2014-11-13) [x86_64-linux]
2015-03-06T09:26:50.762782+00:00 heroku[web.1]: State changed from starting to up
2015-03-06T09:27:01.509095+00:00 heroku[router]: at=info method=GET path="/" host=kulmong.herokuapp.com request_id=4bd004f1-7b04-4cca-883d-09010aa03ee6 fwd="103.7.18.74" dyno=web.1 connect=0ms service=73ms status=404 bytes=1829
routes.rb
Rails.application.routes.draw do
end
Manual create welcome controller and view with routes welcome_controller.rb
class WelcomeController < ApplicationController
# GET /welcome
def index
end
end
Created index.erb in welcome folder at views
<h1>Welcome Rails at heroku</h1>
<p>
Welcome! Hi
</p>
At routes.rb set root to welcome
Rails.application.routes.draw do
resources :projects
root 'welcome#index'
end
projects_controller.rb
Then git add, commit and push to heroku WORK
Only problem is when I try scaffold. It still error with no clue from logs
$ rails g scaffold Project name:String status:String
$ git add .
$ git commit -am 'scaffold Project'
$ git push heroku master
$ heroku open
Goto https://myapp.herokuapp.com/projects
PROBLEM Display
heroku logs (up to this step)
2015-03-06T14:59:36.681043+00:00 heroku[web.1]: Process exited with status 143
2015-03-06T14:59:39.407268+00:00 app[web.1]: [2015-03-06 14:59:39] INFO WEBrick 1.3.1
2015-03-06T14:59:39.407642+00:00 app[web.1]: [2015-03-06 14:59:39] INFO WEBrick::HTTPServer#start: pid=3 port=16123
2015-03-06T14:59:39.407291+00:00 app[web.1]: [2015-03-06 14:59:39] INFO ruby 2.0.0 (2014-11-13) [x86_64-linux]
2015-03-06T14:59:39.904866+00:00 heroku[web.1]: State changed from starting to up
2015-03-06T14:59:47.112131+00:00 heroku[router]: at=info method=GET path="/" host=kulmong.herokuapp.com request_id=e02ce1c1-d787-4182-a6a3-f665d4190403 fwd="103.7.18.74" dyno=web.1 connect=2ms service=26ms status=200 bytes=1411
2015-03-06T14:59:47.490918+00:00 heroku[router]: at=info method=GET path="/assets/application-3942007d31710307dd44000cb1f768c9.css" host=kulmong.herokuapp.com request_id=ad0f7b1f-9f14-4b82-9dbe-0feaf72b3e10 fwd="103.7.18.74" dyno=web.1 connect=1ms service=5ms status=200 bytes=633
2015-03-06T14:59:48.366121+00:00 heroku[router]: at=info method=GET path="/assets/application-47fe71a3b34a93e1929c175b1755d405.js" host=kulmong.herokuapp.com request_id=2e38635a-a76a-4aa4-abf7-f95fd0560716 fwd="103.7.18.74" dyno=web.1 connect=1ms service=53ms status=200 bytes=39912
2015-03-06T14:59:56.493787+00:00 heroku[router]: at=info method=GET path="/" host=kulmong.herokuapp.com request_id=5f98e00e-47a0-4054-8ced-3c4a42a2e2dd fwd="103.7.18.74" dyno=web.1 connect=1ms service=7ms status=200 bytes=1411
2015-03-06T14:59:56.936889+00:00 heroku[router]: at=info method=GET path="/assets/application-3942007d31710307dd44000cb1f768c9.css" host=kulmong.herokuapp.com request_id=a44c2289-a589-4902-acc1-93eb170a2359 fwd="103.7.18.74" dyno=web.1 connect=1ms service=5ms status=304 bytes=204
2015-03-06T15:00:01.756893+00:00 heroku[router]: at=info method=GET path="/projects" host=kulmong.herokuapp.com request_id=d2364420-3aa1-41b0-8f88-f36b51edd88b fwd="103.7.18.74" dyno=web.1 connect=5ms service=22ms status=500 bytes=1754
2015-03-06T15:46:21.167800+00:00 heroku[router]: at=info method=GET path="/" host=kulmong.herokuapp.com request_id=bbfd8332-d09d-4221-b8a0-a705dcef8c1c fwd="103.7.18.74" dyno=web.1 connect=1ms service=8ms status=200 bytes=1411
2015-03-06T15:46:21.647276+00:00 heroku[router]: at=info method=GET path="/assets/application-3942007d31710307dd44000cb1f768c9.css" host=kulmong.herokuapp.com request_id=39ecc6fb-0f39-4670-b326-2b63b53ef289 fwd="103.7.18.74" dyno=web.1 connect=2ms service=11ms status=304 bytes=204
2015-03-06T15:46:22.261151+00:00 heroku[router]: at=info method=GET path="/assets/application-47fe71a3b34a93e1929c175b1755d405.js" host=kulmong.herokuapp.com request_id=d7161d4e-b18c-434b-8fa3-b4f229f96085 fwd="103.7.18.74" dyno=web.1 connect=1ms service=4ms status=304 bytes=218
2015-03-06T15:46:34.182402+00:00 heroku[router]: at=info method=GET path="/" host=kulmong.herokuapp.com request_id=d639726f-ee06-45d4-950b-336b0c1c6168 fwd="103.7.18.74" dyno=web.1 connect=1ms service=8ms status=200 bytes=1411
2015-03-06T15:46:34.612368+00:00 heroku[router]: at=info method=GET path="/assets/application-3942007d31710307dd44000cb1f768c9.css" host=kulmong.herokuapp.com request_id=1ccababa-b634-4182-985b-6e42434123a3 fwd="103.7.18.74" dyno=web.1 connect=1ms service=4ms status=304 bytes=204
2015-03-06T15:46:35.304563+00:00 heroku[router]: at=info method=GET path="/assets/application-47fe71a3b34a93e1929c175b1755d405.js" host=kulmong.herokuapp.com request_id=33473a17-3d52-483e-88f4-556c202fbec9 fwd="103.7.18.74" dyno=web.1 connect=1ms service=4ms status=304 bytes=218
2015-03-06T15:46:36.413113+00:00 heroku[router]: at=info method=GET path="/projects" host=kulmong.herokuapp.com request_id=3046c0c7-3c96-4bcf-bc45-a197acfed716 fwd="103.7.18.74" dyno=web.1 connect=1ms service=16ms status=500 bytes=1754
routes.rb (at this step)
Rails.application.routes.draw do
resources :projects
root 'welcome#index'
end
projects_controller.rb
class ProjectsController < ApplicationController
before_action :set_project, only: [:show, :edit, :update, :destroy]
# GET /projects
# GET /projects.json
def index
@projects = Project.all
end
# GET /projects/1
# GET /projects/1.json
def show
end
# GET /projects/new
def new
@project = Project.new
end
# GET /projects/1/edit
def edit
end
# POST /projects
# POST /projects.json
def create
@project = Project.new(project_params)
respond_to do |format|
if @project.save
format.html { redirect_to @project, notice: 'Project was successfully created.' }
format.json { render :show, status: :created, location: @project }
else
format.html { render :new }
format.json { render json: @project.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /projects/1
# PATCH/PUT /projects/1.json
def update
respond_to do |format|
if @project.update(project_params)
format.html { redirect_to @project, notice: 'Project was successfully updated.' }
format.json { render :show, status: :ok, location: @project }
else
format.html { render :edit }
format.json { render json: @project.errors, status: :unprocessable_entity }
end
end
end
# DELETE /projects/1
# DELETE /projects/1.json
def destroy
@project.destroy
respond_to do |format|
format.html { redirect_to projects_url, notice: 'Project was successfully destroyed.' }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_project
@project = Project.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def project_params
params.require(:project).permit(:name, :status)
end
end
Add gem 'rails_12factor'
group :production do
gem 'rails_12factor'
end
heroku logs after add group production from answer
2015-03-06T17:09:14.952981+00:00 heroku[api]: Deploy c657570 by [email protected]
2015-03-06T17:09:14.952981+00:00 heroku[api]: Release v19 created by [email protected]
2015-03-06T17:09:15.208140+00:00 heroku[web.1]: State changed from up to starting
2015-03-06T17:09:17.078710+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2015-03-06T17:09:17.466316+00:00 app[web.1]: [2015-03-06 17:09:17] FATAL SignalException: SIGTERM
2015-03-06T17:09:17.466324+00:00 app[web.1]: /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/webrick/server.rb:170:in `select'
2015-03-06T17:09:17.466327+00:00 app[web.1]: /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/webrick/server.rb:170:in `block in start'
2015-03-06T17:09:17.466329+00:00 app[web.1]: /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/webrick/server.rb:32:in `start'
2015-03-06T17:09:17.466331+00:00 app[web.1]: /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/webrick/server.rb:160:in `start'
2015-03-06T17:09:17.466333+00:00 app[web.1]: /app/vendor/bundle/ruby/2.0.0/gems/rack-1.6.0/lib/rack/handler/webrick.rb:35:in `run'
2015-03-06T17:09:17.466335+00:00 app[web.1]: /app/vendor/bundle/ruby/2.0.0/gems/rack-1.6.0/lib/rack/server.rb:286:in `start'
2015-03-06T17:09:17.466337+00:00 app[web.1]: /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.0/lib/rails/commands/server.rb:80:in `start'
2015-03-06T17:09:17.466340+00:00 app[web.1]: /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:80:in `block in server'
2015-03-06T17:09:17.466342+00:00 app[web.1]: /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:75:in `tap'
2015-03-06T17:09:17.466344+00:00 app[web.1]: /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:75:in `server'
2015-03-06T17:09:17.466347+00:00 app[web.1]: /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
2015-03-06T17:09:17.466349+00:00 app[web.1]: /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.0/lib/rails/commands.rb:17:in `<top (required)>'
2015-03-06T17:09:17.466352+00:00 app[web.1]: bin/rails:8:in `require'
2015-03-06T17:09:17.466354+00:00 app[web.1]: bin/rails:8:in `<main>'
2015-03-06T17:09:17.466364+00:00 app[web.1]: [2015-03-06 17:09:17] INFO going to shutdown ...
2015-03-06T17:09:17.466366+00:00 app[web.1]: [2015-03-06 17:09:17] INFO WEBrick::HTTPServer#start done.
2015-03-06T17:09:17.466389+00:00 app[web.1]: Exiting
2015-03-06T17:09:18.335257+00:00 heroku[web.1]: Process exited with status 143
2015-03-06T17:09:18.985032+00:00 heroku[web.1]: Starting process with command `bin/rails server -p 32299 -e production`
2015-03-06T17:09:22.606059+00:00 app[web.1]: [2015-03-06 17:09:22] INFO WEBrick 1.3.1
2015-03-06T17:09:22.606082+00:00 app[web.1]: [2015-03-06 17:09:22] INFO ruby 2.2.0 (2014-12-25) [x86_64-linux]
2015-03-06T17:09:22.606506+00:00 app[web.1]: [2015-03-06 17:09:22] INFO WEBrick::HTTPServer#start: pid=3 port=32299
2015-03-06T17:09:22.961214+00:00 heroku[web.1]: State changed from starting to up
2015-03-06T17:10:14.517067+00:00 heroku[router]: at=info method=GET path="/" host=kulmong.herokuapp.com request_id=4bf324fc-d0de-4dfa-800e-62ee04e5e4a2 fwd="103.7.18.74" dyno=web.1 connect=1ms service=28ms status=200 bytes=1411
2015-03-06T17:10:14.487257+00:00 app[web.1]: => Booting WEBrick
2015-03-06T17:10:14.487262+00:00 app[web.1]: => Rails 4.2.0 application starting in production on http://0.0.0.0:32299
2015-03-06T17:10:14.487264+00:00 app[web.1]: => Run `rails server -h` for more startup options
2015-03-06T17:10:14.487266+00:00 app[web.1]: => Ctrl-C to shutdown server
2015-03-06T17:10:14.487267+00:00 app[web.1]: Started GET "/" for 103.7.18.74 at 2015-03-06 17:10:14 +0000
2015-03-06T17:10:14.491090+00:00 app[web.1]: Processing by WelcomeController#index as HTML
2015-03-06T17:10:14.507851+00:00 app[web.1]: Completed 200 OK in 17ms (Views: 7.5ms)
2015-03-06T17:10:14.505187+00:00 app[web.1]: Rendered welcome/index.erb within layouts/application (0.6ms)
2015-03-06T17:10:14.922125+00:00 heroku[router]: at=info method=GET path="/assets/application-3942007d31710307dd44000cb1f768c9.css" host=kulmong.herokuapp.com request_id=58fcd9b2-3ad5-464f-ad23-660d6492ad4a fwd="103.7.18.74" dyno=web.1 connect=1ms service=5ms status=304 bytes=204
2015-03-06T17:10:15.711894+00:00 heroku[router]: at=info method=GET path="/assets/application-47fe71a3b34a93e1929c175b1755d405.js" host=kulmong.herokuapp.com request_id=62f0a025-bb63-4daf-99eb-b3c96f243654 fwd="103.7.18.74" dyno=web.1 connect=0ms service=5ms status=304 bytes=218
2015-03-06T17:10:28.116004+00:00 heroku[router]: at=info method=GET path="/projects" host=kulmong.herokuapp.com request_id=0c2c62f8-363d-478d-a82a-17ea07b65bb5 fwd="103.7.18.74" dyno=web.1 connect=1ms service=17ms status=500 bytes=1754
2015-03-06T17:10:28.104574+00:00 app[web.1]: Processing by ProjectsController#index as HTML
2015-03-06T17:10:28.102356+00:00 app[web.1]: Started GET "/projects" for 103.7.18.74 at 2015-03-06 17:10:28 +0000
2015-03-06T17:10:28.112683+00:00 app[web.1]: Rendered projects/index.html.erb within layouts/application (2.8ms)
2015-03-06T17:10:28.112783+00:00 app[web.1]: Completed 500 Internal Server Error in 8ms
2015-03-06T17:10:28.114586+00:00 app[web.1]:
2015-03-06T17:10:28.114589+00:00 app[web.1]: ActionView::Template::Error (:skip_version_check is an unknown option. Valid options are: :write, :read, :database, :max_retries, :pool_size, :pool_timeout, :retry_interval, :refresh_interval, :down_interval, :ssl, :timeout, :instrumenter, :auto_discover.):
2015-03-06T17:10:28.114591+00:00 app[web.1]: 12: </thead>
2015-03-06T17:10:28.114593+00:00 app[web.1]: 13:
2015-03-06T17:10:28.114594+00:00 app[web.1]: 14: <tbody>
2015-03-06T17:10:28.114596+00:00 app[web.1]: 15: <% @projects.each do |project| %>
2015-03-06T17:10:28.114597+00:00 app[web.1]: 16: <tr>
2015-03-06T17:10:28.114599+00:00 app[web.1]: 17: <td><%= project.name %></td>
2015-03-06T17:10:28.114600+00:00 app[web.1]: 18: <td><%= project.status %></td>
2015-03-06T17:10:28.114602+00:00 app[web.1]: app/views/projects/index.html.erb:15:in `_app_views_projects_index_html_erb___3371573674626367126_70074889855940'
2015-03-06T17:10:28.114604+00:00 app[web.1]:
2015-03-06T17:10:28.114605+00:00 app[web.1]:
Thanks
P.Kul
Upvotes: 3
Views: 2353
Reputation: 1819
When you want to deploy on heroku you must add in your Gemfile
:
group :production do
gem 'rails_12factor'
end
Reference : https://devcenter.heroku.com/articles/getting-started-with-rails4#write-your-app
After testing with your repo you need to delete the options declared on mongoid.yml
:
production:
sessions:
default:
uri: <%= ENV['MONGOLAB_URI'] %>
And it's a good practice to declare a ruby version in you Gemfile
like :
source 'https://rubygems.org'
ruby "2.1.3"
...
Test it on my heroku app : https://tranquil-woodland-7416.herokuapp.com/projects
Upvotes: 5