Posts

Showing posts from April, 2017

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...