From PHP to Ruby on Rails - Bernard Pineda - E-Book

From PHP to Ruby on Rails E-Book

Bernard Pineda

0,0
27,59 €

-100%
Sammeln Sie Punkte in unserem Gutscheinprogramm und kaufen Sie E-Books und Hörbücher mit bis zu 100% Rabatt.

Mehr erfahren.
Beschreibung

Are you a PHP developer looking to take your first steps into the world of Ruby development? From PHP to Ruby on Rails will help you leverage your existing knowledge to gain expertise in Ruby on Rails. With a focus on bridging the gap between PHP and Ruby, this guide will help you develop the Ruby mindset, set up your local environment, grasp the syntax, master scripting, explore popular Ruby frameworks, and find out about libraries and gems.

This book offers a unique take on Ruby from the perspective of a seasoned PHP developer who initially refused to learn other technologies, but never looked back after taking the leap. As such, it teaches with a language-agnostic approach that will help you feel at home in any programming language without learning everything from scratch. This approach will help you avoid common mistakes such as writing Ruby as if it were PHP and increase your understanding of the programming ecosystem as a whole.

By the end of this book, you'll have gained a solid understanding of Ruby, its ecosystem, and how it compares to PHP, enabling you to build robust and scalable applications using Ruby on Rails.

Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:

EPUB

Seitenzahl: 300

Veröffentlichungsjahr: 2023

Bewertungen
0,0
0
0
0
0
0
Mehr Informationen
Mehr Informationen
Legimi prüft nicht, ob Rezensionen von Nutzern stammen, die den betreffenden Titel tatsächlich gekauft oder gelesen/gehört haben. Wir entfernen aber gefälschte Rezensionen.



From PHP to Ruby on Rails

Transition from PHP to Ruby by leveraging your existing backend programming knowledge

Bernard Pineda

BIRMINGHAM—MUMBAI

From PHP to Ruby on Rails

Copyright © 2023 Packt Publishing

All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.

Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing or its dealers and distributors, will be held liable for any damages caused or alleged to have been caused directly or indirectly by this book.

Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.

Group Product Manager: Rohit Rajkumar

Publishing Product Manager: Himani Dewan

Book Project Manager: Aishwarya Mohan

Senior Editor: Rakhi Patel

Technical Editor: Simran Udasi

Copy Editor: Safis Editing

Proofreader: Safis Editing

Indexer: Rekha Nair

Production Designer: Jyoti Kadam

DevRel Marketing Coordinators: Namita Velgekar and Nivedita Pandey

First published: December 2023

Production reference: 1161123

Published by Packt Publishing Ltd.

Grosvenor House

11 St Paul’s Square

Birmingham

B3 1RB, UK

ISBN 978-1-80461-009-1

www.packtpub.com

To my brother Benjamin, who in spite of all that he’s been through keeps on smiling, shining, and thriving.

– Bernardo Pineda

Contributors

About the author

Bernard Pineda has been working in the IT industry since 2002. He worked as a PHP and Ruby on Rails developer for many years, mostly as a freelance developer. He is also a LinkedIn Learning instructor with many courses in both Spanish and English. He has also participated as a speaker on a round table at Campus Party 2010 discussing PHP frameworks. He has written articles regarding Angular and Adobe’s Flex platform. He has worked with different technologies throughout his career, including PHP, Ruby, Java, Python, and Angular, and considers himself a language-agnostic developer. He is currently a site reliability engineer working in the Bay Area. In his spare time, he plays and records music, and also writes screenplays for fun.

I want to thank my wife, Gaby, for all her support during the good times and the bad. She has been the best partner and teammate I could have ever asked for and played a crucial role for me to be able to succeed in this endeavor. I would also like to thank my close friends, who have always pushed me to follow my dreams. Thank you all.

About the reviewers

Ali Onuche John is a distinguished global senior data scientist and enterprise software developer with over 16 years of experience in spearheading the development of ERP software applications across various industries. He also holds the position of CEO at Code Factory, a prominent software development company. Ali’s illustrious career epitomizes a remarkable blend of theoretical expertise and practical finesse, solidifying his status as a maestro at the crossroads of machine learning and software development. Recognized as a thought leader in this field, Ali has left an indelible mark through his notable contributions in the form of publications and workshops. His steadfast dedication to pushing the boundaries of technology is unmistakable, and his perpetual presence at the vanguard of the industry underscores his significant influence in shaping the continually evolving landscape of machine learning and software development. Moreover, Ali brings his valuable experience in the field of climate change, further diversifying his impressive portfolio of expertise and contributions to address critical global challenges.

Melashu Amare is an experienced full stack software engineer who specializes in Ruby, Ruby on Rails, PostgreSQL, Redis, Hotwire, TailwindCSS, RSpec, and Sidekiq. He has contributed to several open source projects and built his own gems. He has also worked as a coding instructor for a few years and has gained extensive experience in mentoring other developers. Before diving into full stack web development, he worked as a mobile application developer using the hybrid mobile application framework Flutter, as well as PHP and MySQL.

Omar Alvarado Luna, a “code investor,” aids businesses in managing code debt through best practices and research. With expertise in PHP, Node.js, Ruby, Bash, and Python, he’s an advocate for cultural and technical best practices. Currently making an impact in the finance and banking sector, his insights enhanced this book. Omar champions methods that drive high-performance teams.

Table of Contents

Preface

Part 1: From PHP to Ruby Basics

1

Understanding the Ruby Mindset and Culture

Technical requirements

Ruby is meant to be read as sentences

Everything is an object

Transitioning to Ruby

Summary

2

Setting Up Our Local Environment

Technical requirements

Installing Ruby locally

macOS users

Windows users

Linux users

Using a virtual machine

VMware

VirtualBox

Vagrant

Using Docker

Using rbenv

Summary

3

Comparing Basic Ruby Syntax to PHP

Technical requirements

Running Ruby code from the command line

Running a simple code file

Loading a source code file with the load method

Loading a source code file with the require method

Ruby classes and modules

The include method

Interactive Ruby Shell (IRB)

Exploring types of variables

Arrays

Hashes

Symbols

Using conditional statements

The if statement

The if-else statement

The ternary operator

Repeating code with loops

Using Ruby language enhancements

The unless sentence

The until loop

Automatic returns

Optional parentheses

Questionable exclamation method names

Summary

4

Ruby Scripting versus PHP Scripting

Technical requirements

Beyond Hello World

Text handling

The upcase method

The downcase method

The capitalize method

File manipulation

The split() method

The map() method

The join() method

Creating and modifying file contents

Command-line arguments

User input

Putting it all together

Summary

5

Libraries and Class Syntax

Technical requirements

Let’s get ready to bundle!!!

Installing a gem

Gemfile versus composer.json

Integrating libraries into your code in Ruby

Declaring classes in Ruby

Objects in Ruby

Attribute accessors

Inheritance in Ruby

Summary

6

Debugging Ruby

Technical requirements

Debugging functions in Ruby versus PHP

Gems for debugging

The debug gem

The pry gem

The byebug gem

Understanding IRB’s usefulness

Summary

Part 2: Ruby and the Web

7

Understanding Convention over Configuration

Technical requirements

If there is Ruby magic, there is Rails magic

Installing Ruby on Rails

Starting our Ruby on Rails project

Rails file structure explained

MVC at its finest

POST, GET, and SESSION in Rails

Summary

8

Models, DBs, and Active Record

Technical requirements

Generating models using Rails

Rails migrations

Connecting to a database

The Rails console

Active Record operations

Creating records

Selecting record(s)

Updating records

Deleting record(s)

Summary

9

Bringing It All Together

Technical requirements

Project preparation

Setting up our application

Processing data

Setting up the CRUD interface

Listing data

Updating data

Creating data

Deleting data

Do not, I repeat, do not repeat yourself

Summary

10

Considerations for Hosting Rails Applications versus PHP Applications

Technical requirements

PHP versus Rails in terms of price

DIY or have it done for you

Why nginx?

Error gossip and last words

Summary

Index

Other Books You May Enjoy

Part 1:From PHP to Ruby Basics

In this part, you will be introduced to the whole Ruby way of doing things while comparing it to the way you would do those things with PHP. In addition to this, you will also learn how to use what Ruby brings to the table in terms of syntax, libraries (called gems), and debugging tools to make troubleshooting as painless as possible.

This part has the following chapters:

Chapter 1, Understanding the Ruby Mindset and CultureChapter 2, Setting Up Our Local EnvironmentChapter 3, Comparing Basic Ruby Syntax to PHPChapter 4, Ruby Scripting versus PHP ScriptingChapter 5, Libraries and Class SyntaxChapter 6, Debugging Ruby