{"id":944,"date":"2019-01-11T15:07:05","date_gmt":"2019-01-11T12:07:05","guid":{"rendered":"https:\/\/artem.services\/?p=486"},"modified":"2019-03-17T17:49:21","modified_gmt":"2019-03-17T14:49:21","slug":"heroku-ruby-on-rails-2","status":"publish","type":"post","link":"https:\/\/artem.services\/?p=944&lang=en","title":{"rendered":"Heroku &#8212; Ruby on Rails"},"content":{"rendered":"<h3><img loading=\"lazy\" class=\"size-full wp-image-497 aligncenter\" src=\"https:\/\/artem.services\/wp-content\/uploads\/2019\/01\/Heroku-Logo.png\" alt=\"\" width=\"596\" height=\"185\" srcset=\"https:\/\/artem.services\/wp-content\/uploads\/2019\/01\/Heroku-Logo.png 596w, https:\/\/artem.services\/wp-content\/uploads\/2019\/01\/Heroku-Logo-300x93.png 300w\" sizes=\"(max-width: 596px) 100vw, 596px\" \/><span class=\"tlid-translation translation\" lang=\"en\"><span class=\"\" title=\"\">System preparation<\/span><\/span><\/h3>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\napt install curl git gnupg2 nodejs\r\n<\/pre>\n<p>Install <strong>RVM<\/strong><\/p>\n<p><span class=\"tlid-translation translation\" lang=\"en\"><span class=\"\" title=\"\">Go to the site<\/span><\/span> <a href=\"https:\/\/rvm.io\" target=\"_blank\" rel=\"noopener noreferrer\">rvm.io<\/a> <span class=\"tlid-translation translation\" lang=\"en\"><span class=\"\" title=\"\"> and look at the installation commands:<\/span><\/span><\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\ngpg2 --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB\r\ncurl -sSL https:\/\/get.rvm.io | bash -s stable\r\n<\/pre>\n<p><span class=\"tlid-translation translation\" lang=\"en\"><span class=\"\" title=\"\">Add a user to the group:<\/span><\/span><\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nvim \/etc\/group\r\n<\/pre>\n<pre>rvm:x:1001:ubuntu<\/pre>\n<blockquote><p><span class=\"tlid-translation translation\" lang=\"en\"><span class=\"\" title=\"\">My username in the system<\/span><\/span> &#8212; <strong>ubuntu<\/strong><\/p><\/blockquote>\n<p>&nbsp;<\/p>\n<p><span class=\"tlid-translation translation\" lang=\"en\"><span class=\"\" title=\"\">Then from the user:<\/span><\/span><\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nsource \/etc\/profile.d\/rvm.sh\r\n<\/pre>\n<p><!--more--><\/p>\n<p><span class=\"tlid-translation translation\" lang=\"en\"><span class=\"\" title=\"\">Find out the version of <strong>RVM<\/strong>:<\/span><\/span><\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nrvm --version\r\n<\/pre>\n<p><span class=\"tlid-translation translation\" lang=\"en\"><span class=\"\" title=\"\">View a list of <strong>Ruby<\/strong> versions available for installation:<\/span><\/span><\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nrvm list known\r\n<\/pre>\n<p><span class=\"tlid-translation translation\" lang=\"en\"><span class=\"\" title=\"\">Install the latest version of <strong>Ruby<\/strong>:<\/span><\/span><\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nrvm install &quot;ruby-2.5.1&quot;\r\n<\/pre>\n<p><span class=\"tlid-translation translation\" lang=\"en\"><span class=\"\" title=\"\">The list of installed <strong>Ruby<\/strong> versions and the default can be found as follows:<\/span><\/span><\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nrvm list\r\n<\/pre>\n<p><span class=\"tlid-translation translation\" lang=\"en\"><span class=\"\" title=\"\">Let&#8217;s see the <strong>gem<\/strong> version and update it:<\/span><\/span><\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\ngem -v\r\ngem update --system\r\n<\/pre>\n<p>Install<strong>Rails<\/strong>:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\ngem install rails\r\n<\/pre>\n<p>&nbsp;<\/p>\n<h3><span class=\"tlid-translation translation\" lang=\"en\"><span class=\"\" title=\"\">Create application<\/span><\/span><\/h3>\n<p><span class=\"tlid-translation translation\" lang=\"en\"><span class=\"\" title=\"\">Create a test application:<\/span><\/span><\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nrails new example_app -T\r\n<\/pre>\n<p><span class=\"tlid-translation translation\" lang=\"en\"><span class=\"\" title=\"\">Go to the directory of our application:<\/span><\/span><\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\ncd example_app\r\n<\/pre>\n<p><span class=\"tlid-translation translation\" lang=\"en\"><span class=\"\" title=\"\">Let&#8217;s create for the test <\/span><\/span><strong><span class=\"tlid-translation translation\" lang=\"en\"><span class=\"\" title=\"\">index.html<\/span><\/span><\/strong><\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nvim public\/index.html\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p><span class=\"tlid-translation translation\" lang=\"en\"><span class=\"\" title=\"\">Insert there the following:<\/span><\/span><\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;!DOCTYPE html&gt;\r\n&lt;html&gt;\r\n    &lt;head&gt;\r\n        &lt;title&gt;Ruby&lt;\/title&gt;\r\n    &lt;\/head&gt;\r\n    &lt;body&gt;\r\nExample Ruby App\r\n    &lt;\/body&gt;\r\n&lt;\/html&gt;\r\n\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p><span class=\"tlid-translation translation\" lang=\"en\"><span class=\"\" title=\"\">Run for test on all interfaces:<\/span><\/span><\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nbundle exec rails s -p 3000 -b '0.0.0.0'\r\n\r\n=&gt; Booting Puma\r\n=&gt; Rails 5.2.2 application starting in development \r\n=&gt; Run `rails server -h` for more startup options\r\nPuma starting in single mode...\r\n* Version 3.12.0 (ruby 2.5.1-p57), codename: Llamas in Pajamas\r\n* Min threads: 5, max threads: 5\r\n* Environment: development\r\n* Listening on tcp:\/\/0.0.0.0:3000\r\nUse Ctrl-C to stop\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p><span class=\"tlid-translation translation\" lang=\"en\"><span class=\"\" title=\"\">Check in the browser:<\/span><\/span><\/p>\n<pre>1.2.3.4:3000<\/pre>\n<blockquote><p><span class=\"tlid-translation translation\" lang=\"en\"><span class=\"\" title=\"\">Where <strong>1.2.3.4<\/strong> is the IP address of the computer where the application is running<\/span><\/span><\/p><\/blockquote>\n<p><span class=\"tlid-translation translation\" lang=\"en\"><span title=\"\">If the computer has a graphical shell, you can omit the<strong> IP<\/strong> address when launching the application, and enter the browser by localhost.<\/span> <span class=\"\" title=\"\">Also without graphics, the localhost can be checked with a cursor or a console browser. <\/span><\/span><\/p>\n<p><span class=\"tlid-translation translation\" lang=\"en\"><span class=\"\" title=\"\">You can stop the application &#8212; <strong>Ctrl-C<\/strong><\/span><\/span><\/p>\n<p>&nbsp;<\/p>\n<h3>Git<\/h3>\n<p><span class=\"tlid-translation translation\" lang=\"en\"><span class=\"\" title=\"\">Being in the root of our application, we initialize the repository:<\/span><\/span><\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\ngit init\r\n\r\nReinitialized existing Git repository in \/home\/ubuntu\/heroku\/example_app\/.git\/\r\n<\/pre>\n<p><span class=\"tlid-translation translation\" lang=\"en\"><span class=\"\" title=\"\">Check status:<\/span><\/span><\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\ngit status\r\n\r\nOn branch master\r\n\r\nNo commits yet\r\n\r\nUntracked files:\r\n  (use &quot;git add &lt;file&gt;...&quot; to include in what will be committed)\r\n\r\n        .gitignore\r\n        .ruby-version\r\n        Gemfile\r\n        Gemfile.lock\r\n        README.md\r\n        Rakefile\r\n        app\/\r\n        bin\/\r\n        config.ru\r\n        config\/\r\n        db\/\r\n        lib\/\r\n        log\/\r\n        package.json\r\n        public\/\r\n        storage\/\r\n        tmp\/\r\n        vendor\/\r\n\r\nnothing added to commit but untracked files present (use &quot;git add&quot; to track)\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p><span class=\"tlid-translation translation\" lang=\"en\"><span class=\"\" title=\"\">Add all files:<\/span><\/span><\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\ngit add .\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p><span class=\"tlid-translation translation\" lang=\"en\"><span class=\"\" title=\"\">And we are doing a commit:<\/span><\/span><\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\ngit commit -am &quot;Add Ruby files to repo&quot;\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p><span class=\"tlid-translation translation\" lang=\"en\"><span class=\"\" title=\"\">Check:<\/span><\/span><\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\ngit status\r\n\r\nOn branch master\r\n\r\nNo commits yet\r\n\r\nChanges to be committed:\r\n  (use &quot;git rm --cached &lt;file&gt;...&quot; to unstage)\r\n\r\n        new file:   .gitignore\r\n        new file:   .ruby-version\r\n        new file:   Gemfile\r\n        new file:   Gemfile.lock\r\n        new file:   README.md\r\n        new file:   Rakefile\r\n        new file:   app\/assets\/config\/manifest.js\r\n        new file:   app\/assets\/images\/.keep\r\n        new file:   app\/assets\/javascripts\/application.js\r\n        new file:   app\/assets\/javascripts\/cable.js\r\n        new file:   app\/assets\/javascripts\/channels\/.keep\r\n        new file:   app\/assets\/stylesheets\/application.css\r\n        new file:   app\/channels\/application_cable\/channel.rb\r\n        new file:   app\/channels\/application_cable\/connection.rb\r\n        new file:   app\/controllers\/application_controller.rb\r\n        new file:   app\/controllers\/concerns\/.keep\r\n        new file:   app\/helpers\/application_helper.rb\r\n        new file:   app\/jobs\/application_job.rb\r\n        new file:   app\/mailers\/application_mailer.rb\r\n        new file:   app\/models\/application_record.rb\r\n        new file:   app\/models\/concerns\/.keep\r\n        new file:   app\/views\/layouts\/application.html.erb\r\n        new file:   app\/views\/layouts\/mailer.html.erb\r\n        new file:   app\/views\/layouts\/mailer.text.erb\r\n        new file:   bin\/bundle\r\n        new file:   bin\/rails\r\n        new file:   bin\/rake\r\n        new file:   bin\/setup\r\n        new file:   bin\/spring\r\n        new file:   bin\/update\r\n        new file:   bin\/yarn\r\n        new file:   config.ru\r\n        new file:   config\/application.rb\r\n        new file:   config\/boot.rb\r\n        new file:   config\/cable.yml\r\n        new file:   config\/credentials.yml.enc\r\n        new file:   config\/database.yml\r\n        new file:   config\/environment.rb\r\n        new file:   config\/environments\/development.rb\r\n        new file:   config\/environments\/production.rb\r\n        new file:   config\/environments\/test.rb\r\n        new file:   config\/initializers\/application_controller_renderer.rb\r\n        new file:   config\/initializers\/assets.rb\r\n        new file:   config\/initializers\/backtrace_silencers.rb\r\n        new file:   config\/initializers\/content_security_policy.rb\r\n        new file:   config\/initializers\/cookies_serializer.rb\r\n        new file:   config\/initializers\/filter_parameter_logging.rb\r\n        new file:   config\/initializers\/inflections.rb\r\n        new file:   config\/initializers\/mime_types.rb\r\n        new file:   config\/initializers\/wrap_parameters.rb\r\n        new file:   config\/locales\/en.yml\r\n        new file:   config\/puma.rb\r\n        new file:   config\/routes.rb\r\n        new file:   config\/spring.rb\r\n        new file:   config\/storage.yml\r\n        new file:   db\/seeds.rb\r\n        new file:   lib\/assets\/.keep\r\n        new file:   lib\/tasks\/.keep\r\n        new file:   log\/.keep\r\n        new file:   package.json\r\n        new file:   public\/404.html\r\n        new file:   public\/422.html\r\n        new file:   public\/500.html\r\n        new file:   public\/apple-touch-icon-precomposed.png\r\n        new file:   public\/apple-touch-icon.png\r\n        new file:   public\/favicon.ico\r\n        new file:   public\/index.html\r\n        new file:   public\/robots.txt\r\n        new file:   storage\/.keep\r\n        new file:   tmp\/.keep\r\n        new file:   vendor\/.keep\r\n<\/pre>\n<p>&nbsp;<\/p>\n<h3>Heroku<\/h3>\n<p><span class=\"tlid-translation translation\" lang=\"en\"><span class=\"\" title=\"\">We register on <\/span><\/span> <a href=\"https:\/\/heroku.com\" target=\"_blank\" rel=\"noopener noreferrer\">heroku.com<\/a> <span class=\"tlid-translation translation\" lang=\"en\"><span class=\"\" title=\"\">and go to the account.<\/span><\/span><\/p>\n<p><span class=\"tlid-translation translation\" lang=\"en\"><span class=\"\" title=\"\">For the convenience of working with <strong>Heroku<\/strong>, install their <strong>CLI<\/strong><\/span><\/span><\/p>\n<p><span class=\"tlid-translation translation\" lang=\"en\"><span class=\"\" title=\"\">\u00a0<\/span><\/span><\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nsudo snap install --classic heroku\r\n<\/pre>\n<p><span class=\"tlid-translation translation\" lang=\"en\"><span class=\"\" title=\"\">Installation for distributions other than Ubuntu can be viewed on the website<\/span><\/span> <a href=\"https:\/\/devcenter.heroku.com\/articles\/heroku-cli#download-and-install\" target=\"_blank\" rel=\"noopener noreferrer\">Heroku<\/a><\/p>\n<p>Check:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nheroku --version\r\n\r\nheroku\/7.19.4 linux-x64 node-v11.3.0\r\n<\/pre>\n<p><span class=\"tlid-translation translation\" lang=\"en\"><span class=\"\" title=\"\">Log in to <\/span><\/span> <strong>Heroku CLI<\/strong>:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nheroku login\r\n<\/pre>\n<p><span class=\"tlid-translation translation\" lang=\"en\"><span class=\"\" title=\"\">We press any key and get the authorization <strong>URL<\/strong>, copy it to the browser, log in. <\/span><\/span><\/p>\n<p><span class=\"tlid-translation translation\" lang=\"en\"><span class=\"\" title=\"\">Let&#8217;s create an application on <strong>Heroku<\/strong>:<\/span><\/span><\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nheroku create\r\n\r\nCreating app... done, \u2b22 my-generated-app-name-83844\r\nhttps:\/\/my-generated-app-name-83844.herokuapp.com\/ | https:\/\/git.heroku.com\/my-generated-app-name-83844.git\r\n<\/pre>\n<p><span class=\"tlid-translation translation\" lang=\"en\"><span class=\"\" title=\"\">Now in the <strong>Gemfile<\/strong> it is necessary to replace &quot;<strong>sqlite3<\/strong>&quot; with &quot;<strong>postgres<\/strong>&quot;, otherwise <strong>Heroku<\/strong> will give the following error:<\/span><\/span><\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nremote: An error occurred while installing sqlite3 (1.3.13), and Bundler cannot\r\nremote: continue.\r\nremote: Make sure that `gem install sqlite3 -v '1.3.13'` succeeds before bundling.\r\nremote:\r\nremote: In Gemfile:\r\nremote: sqlite3\r\nremote:\r\nremote: !\r\nremote: ! Failed to install gems via Bundler.\r\nremote: ! Detected sqlite3 gem which is not supported on Heroku:\r\nremote: ! https:\/\/devcenter.heroku.com\/articles\/sqlite3\r\nremote: !\r\nremote: ! Push rejected, failed to compile Ruby app.\r\n<\/pre>\n<p>Open <strong>Gemfile<\/strong><\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nvim Gemfile\r\n<\/pre>\n<p><span class=\"tlid-translation translation\" lang=\"en\"><span class=\"\" title=\"\">Find at the beginning of the file record of <\/span><\/span><strong><span class=\"tlid-translation translation\" lang=\"en\"><span class=\"\" title=\"\">sqlite3<\/span><\/span><\/strong><\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\ngem 'sqlite3'\r\n<\/pre>\n<p><span class=\"tlid-translation translation\" lang=\"en\"><span class=\"\" title=\"\">And we transfer it to the block<\/span><\/span> &quot;<strong>group :development, :test do<\/strong>&quot;<\/p>\n<p><span class=\"tlid-translation translation\" lang=\"en\"><span class=\"\" title=\"\">To get the following:<\/span><\/span><\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\ngroup :development, :test do\r\n  # Call 'byebug' anywhere in the code to stop execution and get a debugger console\r\n  gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]\r\n  gem 'sqlite3'\r\nend\r\n<\/pre>\n<p><span class=\"tlid-translation translation\" lang=\"en\"><span class=\"\" title=\"\">Before this block, add a new block:<\/span><\/span><\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\ngroup :production do\r\n  gem 'pg'\r\nend\r\n<\/pre>\n<p><span class=\"tlid-translation translation\" lang=\"en\"><span class=\"\" title=\"\">Save changes to the file.<\/span><\/span><\/p>\n<p><span class=\"tlid-translation translation\" lang=\"en\"><span class=\"\" title=\"\">Reinstall without <strong>postgres<\/strong>.<\/span><\/span><\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nbundle install --without production\r\n<\/pre>\n<p><span class=\"tlid-translation translation\" lang=\"en\"><span class=\"\" title=\"\">Add files, commit and push to<\/span><\/span> <strong>Heroku<\/strong>:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\ngit add .\r\ngit commit -am &quot;Heroku&quot;\r\ngit push heroku master\r\n<\/pre>\n<p>Check:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nheroku open\r\n<\/pre>\n<p><span class=\"tlid-translation translation\" lang=\"en\"><span class=\"\" title=\"\">In response, we get the <strong>URL<\/strong> by which we can check the application on <strong>Heroku<\/strong>.<\/span><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>System preparation Install RVM Go to the site rvm.io and look at the installation commands: Add a user to the group: rvm:x:1001:ubuntu My username in the system &#8212; ubuntu &nbsp; Then from the user:<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[399],"tags":[433,689,691,413,693],"_links":{"self":[{"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/posts\/944"}],"collection":[{"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/artem.services\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=944"}],"version-history":[{"count":2,"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/posts\/944\/revisions"}],"predecessor-version":[{"id":949,"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/posts\/944\/revisions\/949"}],"wp:attachment":[{"href":"https:\/\/artem.services\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=944"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/artem.services\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=944"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/artem.services\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=944"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}