rails 5.x –help –

Rails 5.1 is on the board so… lets test it 😉

If you, like me, have multiple versions of rails in your gem libs, than to user proper one do this:

mkdir new_project && cd new_project
vi Gemfile
#add this i.e
source 'https://rubygems.org'

ruby '2.3.0'
gem rails, '~> 5.1.0'

#close vi and v'oila 
$ rails -v
# => Rails 5.1.0
# you may need to cd ../ and cd back to dir, to let changes be visible or sth

So rails –help give us:

Usage:
  rails new APP_PATH [options]

Options:
  -r, [--ruby=PATH]                                      # Path to the Ruby binary of your choice
                                                         # Default: /home/vagrant/.rvm/rubies/ruby-2.3.0/bin/ruby
  -m, [--template=TEMPLATE]                              # Path to some application template (can be a filesystem path or URL)
  -d, [--database=DATABASE]                              # Preconfigure for selected database (options: mysql/postgresql/sqlite3/oracle/frontbase/ibm_db/sqlserver/jdbcmysql/jdbcsqlite3/jdbcpostgresql/jdbc)
                                                         # Default: sqlite3
      [--webpack=WEBPACK]                                # Preconfigure for app-like JavaScript with Webpack (options: react/vue/angular)
      [--skip-yarn], [--no-skip-yarn]                    # Don't use Yarn for managing JavaScript dependencies
      [--skip-gemfile], [--no-skip-gemfile]              # Don't create a Gemfile
  -G, [--skip-git], [--no-skip-git]                      # Skip .gitignore file
      [--skip-keeps], [--no-skip-keeps]                  # Skip source control .keep files
  -M, [--skip-action-mailer], [--no-skip-action-mailer]  # Skip Action Mailer files
  -O, [--skip-active-record], [--no-skip-active-record]  # Skip Active Record files
  -P, [--skip-puma], [--no-skip-puma]                    # Skip Puma related files
  -C, [--skip-action-cable], [--no-skip-action-cable]    # Skip Action Cable files
  -S, [--skip-sprockets], [--no-skip-sprockets]          # Skip Sprockets files
      [--skip-spring], [--no-skip-spring]                # Don't install Spring application preloader
      [--skip-listen], [--no-skip-listen]                # Don't generate configuration that depends on the listen gem
      [--skip-coffee], [--no-skip-coffee]                # Don't use CoffeeScript
  -J, [--skip-javascript], [--no-skip-javascript]        # Skip JavaScript files
      [--skip-turbolinks], [--no-skip-turbolinks]        # Skip turbolinks gem
  -T, [--skip-test], [--no-skip-test]                    # Skip test files
      [--skip-system-test], [--no-skip-system-test]      # Skip system test files
      [--dev], [--no-dev]                                # Setup the application with Gemfile pointing to your Rails checkout
      [--edge], [--no-edge]                              # Setup the application with Gemfile pointing to Rails repository
      [--rc=RC]                                          # Path to file containing extra configuration options for rails command
      [--no-rc], [--no-no-rc]                            # Skip loading of extra configuration options from .railsrc file
      [--api], [--no-api]                                # Preconfigure smaller stack for API only apps
  -B, [--skip-bundle], [--no-skip-bundle]                # Don't run bundle install

Runtime options:
  -f, [--force]                    # Overwrite files that already exist
  -p, [--pretend], [--no-pretend]  # Run but do not make any changes
  -q, [--quiet], [--no-quiet]      # Suppress status output
  -s, [--skip], [--no-skip]        # Skip files that already exist

Rails options:
  -h, [--help], [--no-help]        # Show this help message and quit
  -v, [--version], [--no-version]  # Show Rails version number and quit

Description:
    The 'rails new' command creates a new Rails application with a default
    directory structure and configuration at the path you specify.

    You can specify extra command-line arguments to be used every time
    'rails new' runs in the .railsrc configuration file in your home directory.

    Note that the arguments specified in the .railsrc file don't affect the
    defaults values shown above in this help message.

Example:
    rails new ~/Code/Ruby/weblog

    This generates a skeletal Rails installation in ~/Code/Ruby/weblog.

So what I need is:

rails new app -d postgresql --webpack=react  --skip-coffee -T -B

How ever as usual I’ve got errors i.e

rails  webpacker:install
rails aborted!
Don't know how to build task 'webpacker:install' (see --tasks)
/home/vagrant/.rvm/gems/ruby-2.3.0/gems/railties-5.1.0/lib/rails/commands/rake/rake_command.rb:21:in `block in perform'
/home/vagrant/.rvm/gems/ruby-2.3.0/gems/railties-5.1.0/lib/rails/commands/rake/rake_command.rb:18:in `perform'
/home/vagrant/.rvm/gems/ruby-2.3.0/gems/railties-5.1.0/lib/rails/command.rb:46:in `invoke'
/home/vagrant/.rvm/gems/ruby-2.3.0/gems/railties-5.1.0/lib/rails/commands.rb:16:in `<top (required)>'
bin/rails:4:in `require'
bin/rails:4:in `<main>'
(See full trace by running task with --trace)

So first option -B – skip bundle command – if you don’t have installed gem webpacker – then it will raise the error, second – in Gemfile you have:

gem 'webpacker'

and you need to have:

gem 'webpacker', github: 'rails/webpacker'

than your command:

webpacker:install:react

will work – and one thing! You also need gem 'react-rails'  installed otherwise you’ll get

NoMethodError: undefined method `react' for #<Rails::Application::Configuration:0x00000003e1e5d0>

So if everything is installed and configured you should see

$ rails webpacker:install:react
Webpacker is installed ? ?
Using /var/www/projects/nawidelcu.fit/inchef_app/config/webpack/paths.yml file for setting up webpack paths
Copying .babelrc to app root directory
      create  .babelrc
Copying react loader to /var/www/projects/nawidelcu.fit/inchef_app/config/webpack/loaders
      create  config/webpack/loaders/react.js
Copying react example entry file to /var/www/projects/nawidelcu.fit/inchef_app/app/javascript/packs
      create  app/javascript/packs/hello_react.jsx
Installing all react dependencies
         run  ./bin/yarn add react react-dom babel-preset-react prop-types from "."
yarn add v0.18.1
info No lockfile found.
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
warning Unmet peer dependency "react@^15.5.4".
[4/4] Building fresh packages...
success Saved lockfile.
warning Your current version of Yarn is out of date. The latest version is "0.23.3" while you're on "0.18.1".
info To upgrade, run the following command:
$ sudo apt-get update && sudo apt-get install yarn
success Saved 34 new dependencies.
├─ asap@2.0.5
├─ babel-helper-builder-react-jsx@6.24.1
├─ babel-plugin-syntax-flow@6.18.0
├─ babel-plugin-syntax-jsx@6.18.0
├─ babel-plugin-transform-flow-strip-types@6.22.0
├─ babel-plugin-transform-react-display-name@6.23.0
├─ babel-plugin-transform-react-jsx-self@6.22.0
├─ babel-plugin-transform-react-jsx-source@6.22.0
├─ babel-plugin-transform-react-jsx@6.24.1
├─ babel-preset-flow@6.23.0
├─ babel-preset-react@6.24.1
├─ babel-runtime@6.23.0
├─ babel-types@6.24.1
├─ core-js@1.2.7
├─ encoding@0.1.12
├─ esutils@2.0.2
├─ fbjs@0.8.12
├─ iconv-lite@0.4.16
├─ is-stream@1.1.0
├─ isomorphic-fetch@2.2.1
├─ js-tokens@3.0.1
├─ lodash@4.17.4
├─ loose-envify@1.3.1
├─ node-fetch@1.6.3
├─ object-assign@4.1.1
├─ promise@7.1.1
├─ prop-types@15.5.8
├─ react-dom@15.5.4
├─ react@15.5.4
├─ regenerator-runtime@0.10.5
├─ setimmediate@1.0.5
├─ to-fast-properties@1.0.3
├─ ua-parser-js@0.7.12
└─ whatwg-fetch@2.0.3
Done in 22.23s.
Webpacker now supports react.js ?

Well rails s started successfully and I could see rails starting page (yay!). Anyhow I’d prefer to use react_on_rails gem, and webpacker doesn’t work with this, so according to: https://github.com/shakacode/react_on_rails/issues/232 – I won’t use webpacker.

So what I need is

rails new app -d postgresql --skip-coffee -T

and also bunch of gems:

gem 'simple_form'
gem 'kaminari'
gem 'react_on_rails'
gem 'haml-rails'
gem 'haml'
gem 'paperclip'
gem 'devise', git: 'https://github.com/gogovan/devise.git', branch: 'rails-5.1'
gem 'erubis'
gem 'breadcrumbs_on_rails' gem 'execjs'
gem 'therubyracer', platforms: :ruby group :development, :test do
 # Call 'byebug' anywhere in the code to stop execution and get a debugger console
 gem 'byebug', platform: :mri
 gem 'guard-rspec'

 # gem 'spork'
 gem 'factory_girl_rails'
 gem 'guard-spork'
 gem 'capybara-email'
 gem 'capybara'
 gem 'poltergeist'
 gem 'faker'
 gem 'database_cleaner'
 gem 'cucumber-rails', require: false
 gem 'rspec-rails'
 gem 'pry'
end

with devise problem was:

DEPRECATION WARNING: ActionView::Template::Handlers::Erubis is deprecated and will be removed from Rails 5.2. Switch to ActionView::Template::Handlers::ERB::Erubi instead. (called from <top (required)> at /var/www/projects/nawidelcu.fit/inchef_app/config/application.rb:17)
/home/vagrant/.rvm/gems/ruby-2.4.0/gems/bundler-1.14.6/lib/bundler/runtime.rb:94:in `rescue in block (2 levels) in require': There was an error while trying to load the gem 'devise'. (Bundler::GemRequireError)
Gem Load Error is: undefined method `alias_method_chain' for ActionDispatch::Routing::RouteSet:Class
Did you mean?  alias_method

due to this issue: https://github.com/plataformatec/devise/issues/4511

Ok rails s did work and I’m ready to play 🙂

 

Rafath Khan

Tu powinien być pean na moją cześć, jaki to wspaniały jestem i jakimi niezwykłymi problemami się zajmuję, ale prawda jest taka, że jak każdy człowiek - mam swoje wady i może jakieś zalety. Są momenty, kiedy mam odpowiednią ilość zasobów psychoenergetycznych i mogę przenosić góry, a są niestety i takie momenty, kiedy mi się nawet z łóżka wstać nie chce... nie może tak źle nie jest, ale chętnie bym sobie pospał dłużej... Niemniej jednak, gdy uda się pokonać siebie - satysfakcja jest, ale potem przychodzą kolejne rzeczy, z którymi trzeba się zmierzyć... a na nie, niestety, energii może nie starczyć i tu właśnie wkracza tzw samodyscyplina - powinieneś usiąść i zrobić to coś, a nie siedzieć na kanapie i zajadać się słodyczami i oglądać jakiś nieciekawy serial czy film dla spalenia swojej najważniejszej waluty świata... czasu, którego nie da się odzyskać. I właśnie o tej samodyscyplinie traktować będę na tym blogu + kilka innych tematów, które są mi potrzebne do pracy

Może Ci się również spodoba