Posts

Ruby - Conditionals if - else - elsif

Image
Greetings!!! In this article, we are going to be talking about the control structures inside Ruby.   Control structures are really going to provide the action that happens inside   of our Ruby programs.   It's what's going to decide what takes place under certain circumstances   and the first way that we are going to determine those circumstances is   using conditionals.   So this is, if something is true, we are going to do one thing.   If it's not true, do something else. Right, that's the basic thing.   We will run one set of code under one condition, another under   different conditions.   That's why they are called conditionals.   To do that, we are going to use the syntax of conditionals, which is going to be   if and then a boolean expression and then end at the end and then in between   will be the code that we want to take place if that Boolean value evaluates to true.   So if x is equal to 1 then do ...

Ranges in Ruby

Image
Hey, How are you? In this article, you are going to talk about the Ruby object type for ranges.   Now a range is going to typically be a range of numbers.   Right, so let's say numbers from 1-10.   Well, we could have an array that would contain all of those numbers or we   could simply have a range which will say well, here is the starting point and   here is the end point. It's from 1-10.   Especially if we have something like 1- 1000, it makes a lot more sense to have   something that just tells us the start and end point instead of trying to   construct an array or something that has all 1000 numbers in it.   We can use a range instead.   And there are two kinds of ranges. Array vs Range There is the inclusive range and the exclusive range.   And the notation is right there.   That's how it works.   It's just the first number and then either 2 or 3 dots depending on which   one you want to use. ...

RESTful with RoR

Image
Greetings Mate!!! In this article,   you'll learn about REST and how Rails implements it.   REST is a tricky subject in beginner   Ruby on Rails training.   On one hand, it requires learning   some advanced web concepts and new techniques   at a time when you're still getting   your footing in the basics of MVC and CRUD.   But on the other hand,   REST has become such a core part   of developing in Rails that you must learn it.   So hang with article as you go into some deeper waters.   REST is short for Representational State Transfer ,   and REST is a design concept   which says that our application   should not focus on performing procedures,   but instead on performing   state transformations upon resources. It's not easy to see how that's   different from what we're already doing   because the Rails MVC pattern   already encourages us to break up our code   by model and c...

Ruby Validation Methods

Image
Greetings Mate, In this article,   you will learn how to validate data   in Ruby on Rails.   Validations allow us to make sure   that data meets a set of requirements   before it's saved to the database.   You can think of them as rules   that our data must follow.   We could validate data every time   a form is submitted, in other words,   put our validation code in our controllers,   but that would make it so that the rules   are only enforced when we go through   one of those controller actions.   And then we'd be repeating ourselves   every time we had to go through a controller   that made updates to the same database tables. It's much better to enforce the rules   all the time globally in our application.   And since this concerns the application's   interaction with the database,   the model is the best place for it.   That way the rules will be enforced   right at t...