Posts

CRUD Basics

Image
Greetings of the day!!! In this article,   you will see several concepts   which are important for the design of Rails applications.   These concepts will affect the way that we work with URLs,   how we write controller code,   and how our controllers manage our models and database data.   We're gonna start by talking about the concept of CRUD.   Let's begin with reviewing the MVC web architecture diagram.   You must learned how to use controllers and views   to create dynamic pages and return them back to the browser.   Next, learned to interact   with the database by creating models and associations. MVC Architecture And worked with those, not from a browser,   but via the Rails console would be feasible.   Now, we need to put the two together   and learn how to work with the models   inside our controllers.   Then we'll be able to manipulate   our database data from the browser, ...

Ruby Variable Scope

Image
Welcome Folk, Scope determines whether or not we have access to these variables from inside   classes, methods, and other coded structures and we'll talk more about it once   we introduce those structures, but it's kind of hard to show you examples when   right now we only have our global scope to look at.   So what we've been using so far are local variables, ones where we have nothing in   front of it, and all you really need to know for now is that variable names can   begin with the $ sign or the @ the front of it in order to give it different scopes.  So, $ sign in front of it would give it global scope. Variable Scope   Putting two @ signs in front of it makes it a class variable.   Putting one @ sign in front of it, it becomes an instance variable and you'll be  working with these later on.   For now, just know that these are all legitimate ways that you can name   your variable in Ruby.

Rich Association Traversal

Image
Greetings My Friend, We could gain the ability to add complexity   of other attributes and methods   inside our section edit's model,   we lost something at the same time.   We now have to go through an extra step   to get from one side of the association over to the other.   For example, in our simple, has and belongs to many join,   if we wanted to know all of the admin users   who could edit a page,   we could just request the array of admin users,   page dot admin users and we'd get back an array. It would reach across the join table   to the other side of the association   but in our rich join,   we can't just ask for section's admin users  because there is no direct relationship   between section and admin user.   There's a model that's in between now.   We can still do it,   we just have to go through that extra step   of going through the section edits   and looking up e...

Rich : Many to Many Association

Image
Greetings Geek, In this article, we're gonna add more complexity   to our join tables.   I call these rich joins.   First, to understand why we need this complexity,   let's go back to the many-to-many diagram   for the beginning of this chapter.   This is a classic many-to-many example.   We have a number of courses,   we have a number of students taking these courses.   There will be a table named courses   and a table named students, and in the simple join,   we would have a join table between them,   which we would call courses_students. In the join table will be two foreign keys,   one for the course, and one for the student.   Here's where the simple join falls short, though. Imagine that we wanna keep track of more information   than just the fact that a student   is participating in a class.   You might wanna keep track of their seat number,   or the date they signed up,   or the...

Simple Many to Many Association

Image
Greetings Geeks, We'll begin by looking at a simple join,   and then move on to a more complex join in the next movie.   Many-to-many associations are similar to one-to-many   associations because they also have an object   which has many objects which belong to it.   The difference that as a many-to-many,   the objects don't belong to it exclusively.   For example, a project   has_and_belongs_to_many :collaborators.   The project can have many collaborators,   but the collaborators can also have many projects. It's not like the project owns a collaborator exclusively.   They're allowed to work on other projects, too.   You have a Blog Post, which  has_and_belongs_to_many :categories.   If our Blog Post is both in   the technology and training categories,   it doesn't mean that no other Blog Post can be   in the technology and training categories.   Technology will have many Blog Posts. ...