Image for post
Image for post

📄 Table of Contents

RUBY ON RAILS

Why ROR

POTENTIAL RAILS PROBLEMS AND LIMITATIONS AND HOW TO OVERCOME THEM:

ROR Commands

class SamplesController < ApplicationController
def show
render ‘show’ #this can be omitted
end
end

ROR syntax

def index
render(“hello”)
redirect_to(controller => “demo”, action => “index”)
redirect_to(“http://youtube.com")
end
<%= 5 + 5 %>
<% var = “rubyOnRails” %>
<%= “hello” #{ var } %>
@instance_var =[1, 2, 3, 4, 5]// how to link to other pages
< a href = “/demo/hello” > Hello page </a >
<%= link_to(“page to link to”, {action => “hello”})

VIEWS

Styling in ROR

<h1 style=”color:blue”>Hello Rubyers!</h1><style type=”text/css”> 
h1{color: blue;}
</style>
<%= stylesheet_link_tag 'style.css' %>
Image for post
Image for post

Setup Redis on Mac

brew update
brew install redis
brew services start redis
brew services stop redis
redis-cli ping
redis-server /usr/local/etc/redis.conf
/usr/local/etc/redis.conf
brew uninstall redis
rm ~/Library/LaunchAgents/homebrew.mxcl.redis.plist

Install Elasticsearch on macOS with Homebrew

brew tap elastic/tap
brew install elastic/tap/elasticsearch-full

Install/Check Mongodb on macOS

npm list mongoose
npm list -g  mongoose

Ruby on Rails — HTML.ERB

<% %>   # executes the Ruby code
<%= %> # executes the Ruby code and displays the result

Example

<ul>
<% @products.each do |p| %>
<li> <%= @p.name %> </li>
<% end %>
</ul>
<%=h @user_entered_notes %>

FINALLY, LET’S MERGE IN THE HTML AND ADD SOME ERB

render & render partial:

yield & content_for

<html>
<head>
<%= yield :html_head %>
</head>
<body>
<div id="sidebar">
<%= yield :sidebar %>
</div>
</body>
<% content_for :sidebar do %>
This content will show up in the sidebar section
<% end %>
<% content_for :html_head do %>
<script type="text/javascript">
console.log("Hello World!");
</script>
<% end %>
<html>
<head>
<script type="text/javascript">
console.log("Hello World!");
</script>

</head>
<body>
<div id="sidebar">
This content will show up in the sidebar section
</div>
</body>

How do I auto format Ruby or .erb files in VS Code?

"files.associations": {
"*.html.erb": "html"
}

Use CSS to automatically add ‘required field’ asterisk to form inputs

<div class="required">
<label>Name:</label>
<input type="text">
</div>
<style>
.required:after { content:" *"; }
</style>

Written by

Experience with Front-end Technologies and MERN / MEAN Stack. Working on all Major UI Frameworks like React, Angular.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store