Please explain in dummie terms, what ruby on rails and ajax are, and what they do?

catlady1715

New member
I just finished an html class and css class and I am trying to understand just the concept of RoR and Ajax. I've read several things on the web, but I'm really confused. All they keep talking about is "frameworks" and "application". I'm just not getting the concept or the relationship they have with each other or what they do. All I can figure out is that frameworks might be something like blogger template, and application might be something like googleapps. No one really gives any straight examples of real life uses. Am I close?
 
By framework, they just mean an environment that your code is executed within. This is significant, because there are lots of little "jobs" that need to be completed in order for your code to do what you want it to do. These jobs are routine and tedious, and you as a coder want to spend your time writing your application, not wiring things together. This performs all the grunt work for you, and provides to you many tools that will be helpful for you to write your website's code. Once this framework is set up, you can then go in and create the different parts of your code to do the things that you want it to do. One of those aspects is called the "view" which is what the user sees, this is where your html would be placed, however, in Ruby on Rails, it is interspersed with javascript and even Ruby code itself (which gets rendered into html and javascript before being displayed to the user)

An example of a tool that would be available to you is called a helper, one helper might be the link_to helper, where you could write something like: <%= link_to 'Destroy' , product , :confirm => 'Are you sure?' , :method => :delete %> which might be rendered out to look like this <a href="/products/3" onclick="if (confirm('Are you sure?')) { var f = document.createElement('form'); f.style.display = 'none'; this.parentNode.appendChild(f); f.method = 'POST'; f.action = this.href;var m = document.createElement('input'); m.setAttribute('type', 'hidden'); m.setAttribute('name', '_method'); m.setAttribute('value', 'delete'); f.appendChild(m);var s = document.createElement('input'); s.setAttribute('type', 'hidden'); s.setAttribute('name', 'authenticity_token'); s.setAttribute('value', 'o/Q+gEE+NJJFxKvs7crhj9MDLBZf+0PRgGA2NOPejmY='); f.appendChild(s);f.submit(); };return false;">Destroy</a>

You wouldn't wnat to have to write all that stuff :P it is generated for you, and it is even specific to the product contained in the product variable (this is something specific to your website, if it was a blogging website, then you might have a blog instead of a product, or if it was a reviewing website, this might be review), notice the url is product/3 this is the product in your database with the id of 3, so if you have a bunch of products, you can just loop through them all, and it will adjust the path to be correct for whichever product is currently being considered.

Another example is that you are going to need to talk to the database, that's a lot of stuff to deal with, a lot of configuration files to write, a lot of information to keep track of. Rails has a whole system called migrations set up to track changes for you, implement changes for you, update and roll back the state of your database. Whats even better is that this is all written in Ruby, which means that it is database independent. You are not tied to whatever database you wrote the code in, because the actual code used to talk to the database is generated depending on your Ruby code. If you change databases, the generated code will change, but the code that you wrote does not need to, so you are not tied to a specific database because of your code.

These are examples of how it helps you, how it makes life simpler, how it performs the tedious tasks for you, how it "wires" your website together for you.

-----

AJAX is a way that the browser can talk to your website without refreshing the page. In HTML, after each request to the server, you are effectively cut off, it is as if you are offline. Your browser does not communicate with the server when you aren't doing anything. For example, if you were to shut off your internet right now, this page you are reading would still be here exactly as is. Each time you follow a link or refresh a browser, or do something like this, your browser re-establishes communication with the server, uses a cookie to identify itself to the server, and then the server performs whatever is expected of it, and returns whatever file the browser has asked for, or does whatever action the browser has told it to do.

The problem here, is that sometimes you want data to update dynamically, it can be a real hassle to reload the browser for every small change. This is where AJAX comes in, it allows the browser to change it's DOM (essentially it's code) by going to the server behind the scenes, connecting, making whatever request it needs to, and then taking what the server has returned to it, and updating the page that you are viewing. For example, if you go to FaceBook, it might pop up a little icon saying that a post has been made since you were viewing your wall, it knows this because it asks the browser what is going on, the browser tells it, and then it informs you. How irritating would it be if you were reading some comment someone wrote, and it just refreshed itself in order to show you the new post, you'd lose your place. At the same time, you might want to know that some new post has been made, but wouldn't be able to
 
Back
Top