Category Archives: Ruby on Rails

Install Ruby on Rails 7 on Linuxmint

If you would like to try Ruby on Rails 7 with Ruby 3 on Linuxmint 20.03, I am quickly going to demonstrate how to install Ruby, Node, NPM, Yarn, git, build essentials, Ruby on Rails 7 and all other required packages and also will create the demo Rails app and run the Rails server and pull up the rails app in my preferred web browser. There a screencast video of the process that you can find at bottom of the page.

sudo apt install curl
curl -sL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
sudo apt-get update
sudo apt-get install git-core zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev software-properties-common libffi-dev nodejs yarn -y
cd 
git clone https://github.com/rbenv/rbenv.git ~/.rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrcexeexec $SHELLc $SHELL
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
exec $SHELL
git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bashrc
exec $SHELL
rbenv install 3.1.2
rbenv global 3.1.2
ruby -v
gem install bundler --no-document
gem install rails -v 7.0.2.4 --no-document
rbenv rehash
rails -v
cd Desktop 
rails new demo_app
cd demo_app
rails server
http://localhost:3000

Print Pyramid Patterns with Ruby Language

Here is a quick approach to print pyramid patterns with Ruby Language. It’s a simple and easy approach that anyone can easily understand and try on their own. I am taking rows value in every for-in loop, but I have just mentioned once on the very first code block. I just updated the all the code blocks with gets method to take rows value from the user.

#1

print "Enter Number for Rows", ": "

rows = gets.chomp.to_i

for row in 0..rows
	row.times {print "*"}
	puts
end
*
**
***
****
*****

#2



print "Enter Number for Rows", ": "

rows = gets.chomp.to_i


for row in 0..rows
	(rows-row).times {print "*"}
	puts
end
*****
****
***
**
*

#3



print "Enter Number for Rows", ": "

rows = gets.chomp.to_i


for row in 0..rows
	(rows-row).times {print " "}
	row.times {print "*"}
	puts
end
    *
   **
  ***
 ****
*****

#4



print "Enter Number for Rows", ": "

rows = gets.chomp.to_i


for row in 0..rows
	row.times {print " "}
      	(rows-row).times {print "*"}
	puts
end
*****
 ****
  ***
   **
    *

#5



print "Enter Number for Rows", ": "

rows = gets.chomp.to_i


for row in 0..rows
	(rows-row).times {print " "}
	row.times {print "*"}
	(row-1).times {print "*" }
	puts
end
    *
   ***
  *****
 *******
*********

#6



print "Enter Number for Rows", ": "

rows = gets.chomp.to_i


for row in 0..rows
	row.times {print " "}
	(rows-row).times {print "*" }
	(rows-row-1).times {print "*"}
	puts
end
*********
 *******
  *****
   ***
    *

#7



print "Enter Number for Rows", ": "

rows = gets.chomp.to_i


for row in 0..rows
	(rows-row).times {print " "}
	row.times {print "*"}
	(row-1).times {print "*" }
	puts
end

for row in 0..rows
	row.times {print " "}
	(rows-row).times {print "*" }
	(rows-row-1).times {print "*"}
	puts
end
    *
   ***
  *****
 *******
*********
*********
 *******
  *****
   ***
    *

Here is the code for all the patters mentioned above in one ruby file. If you would like, you can copy the code and run it on your system.

print "Enter Number for Rows", ": "

rows = gets.chomp.to_i

for row in 0..rows
	row.times {print "*"}
	puts
end


puts "-------------------"

# decreasing pattern
for row in 0..rows
	(rows-row).times {print "*"}
	puts
end


puts "-------------------"

for row in 0..rows
	(rows-row).times {print " "}
	row.times {print "*"}
	puts
end

puts "-------------------------"
for row in 0..rows
	row.times {print " "}
      	(rows-row).times {print "*"}
	puts
end

puts '------------------------'
for row in 0..rows
	(rows-row).times {print " "}
	row.times {print "*"}
	(row-1).times {print "*" }
	puts
end

puts "=========================="

for row in 0..rows
	row.times {print " "}
	(rows-row).times {print "*" }
	(rows-row-1).times {print "*"}
	puts
end

# these two FOR loops run togather
for row in 0..rows
	(rows-row).times {print " "}
	row.times {print "*"}
	(row-1).times {print "*" }
	puts
end

for row in 0..rows
	row.times {print " "}
	(rows-row).times {print "*" }
	(rows-row-1).times {print "*"}
	puts
end



Gem Install Rails Bundler Without Documentation

Make your ruby Gem install and Bundler update ruby gems like crazy fast with new commands. This will let you install rails and all other gems install without documentation. gem install rails –no-docs does not work.

Install Gem Without rdoc and ri

The old –no-rdoc and –no-ri have been merged into one –no-document

gem install rails --no-document

Create .gemrc file

Create .gemrc file in home directory and put the following commands and save the file.

install: --no-document
update: --no-document

or

gem: --no-document

Restart Terminal

After adding this command to .gemrc file, your gem install and bundle commands will not install rdoc and ri files for any gem you would install and this will make gem i and bundler update ruby gems like crazy fast.

On Linux

nano ~/.gemrc

nano will create .gemrc file in your home directory and now you’ll have to just write the following line and overwrite and save the file and restart the terminal.

gem: --no-document

On Windows 10

Just open your cmd and type open . create a file .gemrc in your user’s folder and type the same and save the file and restart the cmd.

gem: --no-document

Rails 6 Tutorial: Create Your First App

Learn Ruby on Rails 6: This Rails 6 tutorial will help you create your very first app. You’ll learn the basic of Ruby on Rails 6 and once you have understood the basics of Ruby on Rails 6 – you would be on the way to creating your dream app.

Rails Action Text

Action Text add rich text editing experience to Rails app. It create a model call Rich Text, that can be associated to any existing model record and it exploits Active Storage to store its media data like images.

If Rails Action Text Does not show images

Behind the scenes rails uses imagemagick to style and manipulate images; make sure you already have installed imagemagick on your system before start using Active Storage and Action Text.

http://imagemagick.org

Watch me implement Action Text in Rails App

https://youtu.be/D5v-i6aM9ZA

How to Install Ruby on Rails 6 on Windows 10

Download & Install Ruby on Windows

You can now install both Ruby 2.6 and DevKit together from rubyinstaller website. But if you only need ruby to be installed on your windows system, just download any ruby 2.x version from Ruby without DevKit download section.

https://rubyinstaller.org/downloads/
Download Ruby 2.6.x version without DevKit

Download & Install DevKit on Windows

If you wish to install Ruby on Rails on Windows then you’ll require DevKit, which helps C-extensions compile immediately. Previously DevKit was downloaded and installed separately on Windows systems. Now, both ruby and DevKit can be installed together with just one click from rubyinstaller website.

Download both Ruby 2.6.x and DevKit together

To install Ruby on Rails, you need to install ruby with DevKit. Once your ruby is installed, check the ruby version with following command.

ruby -version

Install NodeJS and Yarn for Ruby on Rails

install nodejs for rails

You’ll require Nodejs and Yarn to be installed before your start installing Rails 6.

Download & Install NodeJS

To install NodeJS, simply visit nodejs.org and download the latest or the stable version of Node and install it. With Node installation, you get nodejs, npm, and npx but yarn needs to be installed once you have nodejs installed on your system.

Install Yarn for Rails

npm i -g yarn
Watch me install Nodejs and Yarn on Windows 10

Let’s install Ruby on Rails 6

To install Ruby on Rails 6 without document. I do not prefer installing docs just because it takes time and space on the system.

gem install rails --no-document

It takes time. I know. After Rails is installed. Just create a demo app to test if Rails Development environment is set up properly.

rails new demoapp
cd demoapp
rails server

There is possibility that you’ll get errors, to fix errors scroll down. I have listed few common errors with solutions.

Rails Posts you might like

  1. Rails 6 Tutorial – Create your first app
  2. Install Rails without Documentation
  3. How to Install Ruby on Rails 5.1.4 on Ubuntu 16.04 / 17.04

Watch me install Ruby on Rails on Windows

Watch me install Ruby on Rails on Windows 10

Rails sqlite3 gem error – Windows 7/8/10

replace gem sqlite3

Replace gem sqlite3 with the following code and run bundle install

gem 'sqlite3', '~> 1.4'

replace with

gem 'sqlite3', git: "https://github.com/larskanis/sqlite3-ruby", branch: "add-gemspec"

or..

gem ‘sqlite3’, ‘~> 1.3’

or ..

gem 'sqlite3'

One of the above must work with your setup, then

bundle install && rails server

RAILS_ENV=development environment is not defined

Simply run the following command, make sure you have already installed nodejs and yarn

rails webpacker:install

Now go ahead and run bundle install and rails server

bundle install 

rails server

ActiveRecord::ConnectionNotEstablished

No connection pool with ‘primary’ found.

Replace the following line in Gemfile

gem 'sqlite3', '~> 1.4'

with

gem "sqlite3"

Puma caught this error: Error loading the ‘sqlite3’ Active Record adapter

In Gemfile replace sqlite3 gem with following command and bundle install

gem 'sqlite3'

Now,

bundle install && rails server

Now run bundle install and rails server