Getting Started with Ruby on Rails
- 16 hours on-demand video
- 37 downloadable resources
- Full lifetime access
- Access on mobile and TV
- Certificate of Completion
Get your team access to 4,000+ top Udemy courses anytime, anywhere.Try Udemy for Business
- Basics of Ruby
- The MVC architecture of Rails
- How Rails supports the Development of Models
- How Rails supports the Development of Views
- Best Practice in the use of HTML5 and CSS3
- Best Practice in Behavioural Driven Development
- How to use an extensive range of Ruby Gems to maximise productivity
- CSS3 Animations
- Responsive Design
This lecture introduces the goals of the course, and then moves on to some Ruby basics, followed by a picture of the Rails framework. It's a fairly light-weight lecture so let it all wash over you and get ready for a bit more work next time.
Installing Ruby on Rails on your own machine can be a real pain point. I strongly recommend using the Nitrous.io development environment "in the cloud". It all works smoothly and enables you to get straight into learning Ruby and Rails. This lecture shows you how to get started with Nitrous.
The Nitrous Desktop is now available for both Windows and Mac. It enables you to synchronise files between Nitrous and your local machine. This means you can (a) keep a local copy of your Nitrous project, and (b) edit the project with an editor on your own machine and have it synchronise with the project in Nitrous. At the end of the lecture I introduce the Interactive Ruby Console (IRb) that will be used in the next few lectures on Ruby.
Now you have some familiarity with Ruby, it is worth getting to know the IRb (Interactive Ruby) tool a little better to enable you to explore the language. This lecture contains some worked examples of using the IRb to introduce the basic commands and some of the cool things you can do if you want to experiment with Ruby.
This handout contains an extended coding example in Ruby in order to provide a little more detail about some aspects of the language. It also contains a few simple exercises to test your understanding. Answers to these will be available in the supplementary material section.
Now we can start to take a look at Rails. In this lecture, I will provide a quick reminder of the details of the MVC architecture, show some basics of using embedded Ruby to generate content for View files and finally use Rails' generated links to navigate between pages.
An archive of the complete project that was created for this lecture can be found in the supplementary material. I do strongly recommend taking the trouble to type up the code for the project by hand first, but you may find the archive useful to refer to if you have any problems.
This lecture introduces the larger sample application that we will use for the remainder of the course. We will explore rails routes a little more, and then introduce the layout file that fleshes view files out into complete html documents. Finally, we will introduce helpers, that can be used to customise view files.
In this lecture, we will introduce the use of Rails' "partials" to capture small reusable chunks of html content. Specifically, we will use partials to capture the header, footer and nav bar for our website.
We will also take another look at our routes, and introduce the Rails "link_to" method.
Process is important. It is particularly important when you are working with a team. But even if you are working on your own, using the techniques and tools that I will introduce you to in this chapter will protect you from a number of potential disaster scenarios, and help to ensure that you deliver a quality product to your customer.
This opening lecture provides a short overview of the material that will be covered in the rest of this chapter.
There are two broad choices for a Rails development environment. Many prefer the lightweight command line plus programmer's editor route. The alternative is to use a full fledged IDE. I will talk about both in this lecture.
I will also briefly cover the options for backend database.
Having developed well specified and tested code, you will now want to maintain it in a carefully managed repository,won't you! In this lecture we will review the fundamentals behind the distributed version control system Git, and show you how to set up a remote repository in GitHub.
We will replace the static Events page with a dynamically generated index of Events in this lecture. This will introduce you to Rails' Active Record. This manages the Object-Relational mapping that takes care of the relationship between a Rails model at its persistent representation in the database. We will use a scaffold generator to produce the: events controller; all the views that correspond to actions in the controller; an update to the routes.rb file; the database migration; and, of course, the Event.rb class for the model itself.
We have generated a model with a CRUD interface so that users may add and update events. But we also need to ensure that all the data that must be provided before an event is saved, is indeed provided - and in the correct format. For that we use Rails Validations. Even more importantly, we need to ensure that only authorised users change data. We introduce Ruby's Action Callbacks and then use these to place an authentication layer on those actions whose access needs to be controlled. Rather than code up authentication from scratch, we will use the Devise gem. This will also introduce you to the use of Ruby Gems.
Building Associations between classes is so easy in Rails. This lecture demonstrates how we can use Active Record to build a one-to-many association between two classes in a model. We also show how to ensure that dependent objects are destroyed automatically when a parent object is destroyed.
Rails has some impressive support for Model Building in Active Record. The key thing about this is that (a) Rails uses conventions to free you from the routine configuration of your model implementation, and (b) you are now free to think deeply about your domain model. In this lecture we will say a little more about the association types that are supported by Active Record, but more importantly, start to show you how to think deeply about your models. Be very clear about this. No matter how good you are at developing Rails apps, there will always be someone who is better. But your Model is going to remain your unique selling point - you have to get it right!
You will find a zip file containing the complete code for the project so far under the Resources section. This should have all the links correctly setup as per the discussions around this lecture, but do send me a message if I have missed anything.
As we build up content in this Chapter, we will also start to style our sample web application. Before we commit to styling we need to pull together a Boilerplate of best practice to handle cross-browser compatibilities and other known issues to ensure our application has a consistent look and feel.
CSS can do magic, but it also does a lot of things badly.
Sassy CSS sorts out the issues properly and makes CSS truly DRY. We will first introduce Sprockets - a general purpose tool for managing asset pipelines. Then we will show how SCSS enables you to define and structure your styling assets much more effectively than was possible with vanilla CSS.
This lecture looks in detail at the mappings from Routes to Controller Actions that are automatically generated for you when you declare a Resource in Rails. As well as simplifying the navigation through your application, it also automatically generates a public facing RESTful API for you. We will show how to make this API respond to requests for different representations of a resource.
Ruby Gems enable you to extend Rails Core with best practice solutions for many of the common programming problems that are found when building Rails Apps. These are easy to plug into your project and offer mature and stable enhancements. We will explore some of the best in more detail in the remainder of the lectures in this chapter.
Active Admin is a rich and powerful Gem for generating the back end Administration functionality for a Rails Web Application. It includes Devise for authentication, and use Formtastic to generate the forms it uses. It is highly recommended, and extensively used by the Rails community to provide the Administration components of web applications.
N.B. Some of you have seen a clash between the earlier installation of Devise and Active Admin. As a result, you may find it easier/safer to start this lecture with a clean build of the sample application that has not got Devise installed. The archive file that is available here as a download should provide a good starting point. Once you have unzipped the file, you will need to cd into its root directory, bundle install and migrate the database to the current version. Then check it runs okay. Once that is done, you can install Active Admin as per this lecture. Note that once you have installed Active Admin, you will need to add the authentication filters in as per Lecture 14 - this includes adding in the sidebar that is described in Slide 17 of that lecture. (Note also that the before_filter you need to use is: authenticate_user!.
These two gems offer complementary functionality. CarrierWave supports upload of media files into a Web Application. RMagick provides some extremely useful image processing capability. We will see how these two gems can work together to enable us to add the capability to upload image files, and have them automatically resized into versions that are suitable for different uses in our Sample Application.
I give a quick summary of where we are, and then provide some pointers to sources of material for continuing the adventure.
If you are ready to take a more intensive web development course, Bloc offers a Developer Apprenticeship. You can save $100 on enrollment with the coupon code "learnrails".
How Bloc Works:
- Continuous coaching: Meet 3 times per week, one-on-one, with a Bloc mentor vested in your success.
- Intensive: Bloc is a results-focused program with a 25 hour/week commitment.
- Real-World projects: You'll build clones of Reddit, Wikipedia, Kissmetrics, and Google Reader and learn industry standard tools.
- Jump-start your passion project: As your final capstone project, you'll build your own Ruby on Rails website from scratch with your mentor's help.
This lecture covers more detail about Git. While much of the focus is on the use of Git's capability for using branches, a number of other important features are introduced. Once you have gone through this lecture you should have enough information to both work on your own projects and contribute to a shared project.
The two key lessons of this lecture are:
- Follow the HTML5 recommendation of declaring your document as using the UTF-8 Unicode encoding scheme;
- Once you have done that, eliminate (as far as is possible) character references.
- Some experience in computer programming
- Ideally some experience in Object Orientation
This course covers all you need to get started with building Web applications with Ruby on Rails. It takes you from basic material on the best practices that are embedded into the Rails framework, through to advanced material on developing real time applications with Rails.
The course contains screen casts and practical examples. We show you how to get coding right away using Nitrous - a cloud based development environment. So there is no need to spend time on the tedious business of installing tools on your own machine.
I am not a full-time teacher. My courses are informed by extensive real-world application development both in industry and academia. So I teach you what works in practice, and by following this course you will benefit from my 35 years' experience in a wide range of software engineering projects.
- Those with a wish to gain a broad foundation in the technology and processes needed for developing Web Applications with Ruby on Rails.