How I Learned Ruby on Rails in Three Nights.  And I never learned.  Why Ruby on Rails is one of the best early programming languages ​​for designers First ruby ​​on rails project

How I Learned Ruby on Rails in Three Nights. And I never learned. Why Ruby on Rails is one of the best early programming languages ​​for designers First ruby ​​on rails project

One of the first and most comprehensive Rails tutorials on the web. The main advantage is a detailed coverage of the most necessary issues, regular updates and free content.

True, the resource is completely in English. And it is important to understand that this is built in the form of a book - you have to figure out all the issues yourself. Because of this, the duration and complexity of training cannot be predicted.

2. Railcasts

Another well-known on the Internet training resource. More than one generation of Rails developers grew up on it. Also in English.

It is not built as a holistic training course, but as a series of screencasts - short lessons on a specific topic. There are a lot of lessons, you can find almost any topic.

Unfortunately, the project stopped being updated in 2013.

3. Rails for Zombies

A kickass introduction to rails for beginners in a quest-style game with a zombie vibe. It is very popular among complete beginners.

It is convenient that you do not need to install anything on your computer. All puzzles are solved in the browser. Step by step you go through the game and begin to understand the basics of Ruby on Rails.

If you don't understand programming at all, this is your choice. There are no complex topics in the course, nothing distracts from the basics. In English.

3. Udemy

Large collection of video courses. Among them are many on ruby ​​and ruby ​​on rails. It makes no sense to give specific links - choose according to your taste by price or popularity.

The Udemy format involves fairly short courses with an emphasis on video lessons. Do not expect serious homework or prompt support from teachers.

4. Ruby Bursa

A powerful short course on the basics of Rails development. Experienced teachers, good program.

On the course, the personal presence of the student is desirable and it takes place only in large Ukrainian cities.

5. Development on Ruby on Rails from Evil Martians

A three-day intensive from one of the most experienced Ruby on Rails teams in Russia.

Rarely done. It is expensive (judging by the reviews, it's worth it). Requires personal presence. Suitable only for advanced programmers, there is nothing for beginners to do there.

6. Ruby on Rails Online Intensive from Good Programmer

A fresh project from a team known on Youtube for their Ruby courses for beginners.

The 3-month intensive program is designed for complete beginners and promises to make you a junior programmer with a portfolio of nothing more than 12 smart applications.

The course consists of video lessons, practical tasks, teacher support, regular webinars.

Judging by the youtube channel and user comments, these guys know what they are doing and you will not be bored with them.

In this article, I want to show you how to create a simple MySQL database application in Ruby on Rails 3 environment. You can consider this material as a step-by-step guide for beginner Rails programmers.

So, for work we need installed rails and rubygems. I had a problem with the latter yesterday, so I had to remove the rubygems1.8 package, which was not clear how it ended up in the system, and install rubygems1.9. Let me remind you that I develop on Ubuntu, although I think the Rails console commands will be the same for Windows. I use NetBeans as a development environment with a plugin for Ruby on Rails. About the installation is well written in my colleague.

Link checking

You need to make sure that the /usr/bin directory contains rails, rake, ruby, bundler symbolic links to files from the /usr/local/ruby/bin directory. To view links, use the command:

depending on what you want to filter.

We create an application

I have created a special directory for my ruby ​​applications.

mkdir /home/andrey/ruby
cd /home.andrey/ruby

Rails has a lot of console utilities that make things a lot easier, especially when it comes to prototyping. To create an application using mysql as a database, run the command:

app is the name of our new application. After executing the command, we will see how rails made the framework of the future application for us.

[email protected]:~/ruby# rails new app -d mysql
create
create README
create Rakefile
create config.ru
create .gitignore
create gemfile
create app
create app/controllers/application_controller.rb
create app/helpers/application_helper.rb
create app/mailers
create app/models
create app/views/layouts/application.html.erb
create config
create config/routes.rb
create config/application.rb
create config/environment.rb
create config/environments
create config/environments/development.rb
create config/environments/production.rb
create config/environments/test.rb
create config/initializers
create config/initializers/backtrace_silencers.rb
create config/initializers/inflections.rb
create config/initializers/mime_types.rb
create config/initializers/secret_token.rb
create config/initializers/session_store.rb
create config/locales
create config/locales/en.yml
create config/boot.rb
create config/database.yml
create db
create db/seeds.rb
create doc
create doc/README_FOR_APP
create lib
create lib/tasks
create lib/tasks/.gitkeep
create log
create log/server.log
create log/production.log
create log/development.log
create log/test.log
create public
create public/404.html
create public/422.html
create public/500.html
create public/favicon.ico
create public/index.html
create public/robots.txt
create public/images
create public/images/rails.png
create public/stylesheets
create public/stylesheets/.gitkeep
create public/javascripts
create public/javascripts/application.js
create public/javascripts/controls.js
create public/javascripts/dragdrop.js
create public/javascripts/effects.js
create public/javascripts/prototype.js
create public/javascripts/rails.js
create script
create script/rails
create test
create test/fixtures
create test/functional
create test/integration
create test/performance/browsing_test.rb
create test/test_helper.rb
create test/unit
create tmp
create tmp/sessions
create tmp/sockets
create tmp/cache
create tmp/pids
create vendor/plugins
create vendor/plugins/.gitkeep

We go into the folder with it and install the necessary gems. Gems are plug-in libraries required for a project (similar to PHP's PECL and PEAR).

After that, the console will have something like this:

[email protected]:~/ruby/app> sudo bundle install
Using rake (0.8.7)
Using abstract (1.0.0)
Using active support (3.0.0)
Using builder (2.1.2)
Using i18n (0.4.2)
Using activemodel (3.0.0)
Using erubis (2.6.6)
Using rack (1.2.1)
Using rack-mount (0.6.13)
Using rack-test (0.5.6)
Using tzinfo (0.3.23)
Using actionpack (3.0.0)
Using mime-types (1.16)
Using polyglot (0.3.1)
using treetop (1.4.8)
Using mail (2.2.9)
Using actionmailer (3.0.0)
Using arel (1.0.1)
Using activerecord (3.0.0)
Using active resource (3.0.0)
Using bundler (1.0.3)
Using mysql2 (0.2.6)
Using thor (0.14.4)
Using railties (3.0.0)
Using rails (3.0.0)
Your bundle is complete! Use `bundle show ` to see where a bundled gem is installed.

This means that all gems are installed and connected. If something is missing, then the bundle itself will download them from rubygems and install them. This is what I have been missing in php for a long time, in fact it turns out to be a project installer. The list of dependent gems is located in the Gemfile at the root of the project.

Configuration

Now we need to specify the details of access to the database of our project. Open the project in NetBeans: New Project -> Ruby -> Ruby on Rails application with existing source. Specify the path, in my case it will be (/home/andrey/ruby/app) and the name of the project (app). As the Ruby Platform, we select the one installed in the system, and not the one built into NetBeans. Click Finish and the project is created. Open the Configuration pseudo-folder and the database.yml file. Here you need to specify a login and password to access the database, preferably for all three environments at once (development, test, production). The environment is the environment in which our application will run,

  • development - developer's computer,
  • production - production server,
  • test - work in test mode on the continuous integration server or tester's computer.

rails generate model User name:string hashed_password:string salt:string

You can immediately see what Rails has generated for us:

invoke active_record
create db/migrate/20101107054200_create_users.rb
create app/models/user.rb
invoke test_unit
create test/unit/user_test.rb
create test/fixtures/users.yml

Ok, now we need to create a database. We execute for this:

[email protected]:~/ruby/app$ rake db:create
(in /home/andrey/ruby/app)
[email protected]:~/ruby/app$ rake db:migrate
(in /home/andrey/ruby/app)
== CreateUsers: migrating ============================================ =======
- create_table(:users)
-> 0.0061s
== CreateUsers: migrated (0.0063s) ======================================== ==

The console outputs the added data. We look in phpmyadmin and see the new app_development and app_test databases, as well as the tables in them. Now it's time to add the real data. To do this, launch the rails console

The console is not just a console, but an IRB console in the context of your application. Let's create two users as an example:

[email protected]:~/ruby/app$ rails console
Loading development environment (Rails 3.0.0)
irb(main):001:0> user1 = User.new
=> #
irb(main):002:0> user1.name = "andrey"
=> "andrey"
irb(main):003:0> user1.save
=> true
irb(main):004:0> user2 = User.new
=> #
irb(main):005:0> user2.name = "vasily"
=> "vasily"
irb(main):006:0> user2.save
=> true

irb(main):007:0> exit
[email protected]:~/ruby/app$

Let's look at the database, and indeed we have two users. Note that Rails itself added primary key columns and created_at (creation date) and updated_at (modified date) fields to the model.

We have the model, the data too. It's time to launch our application.

[email protected]:~/ruby/app$ rails server
=> Booting WEBrick
=> Rails 3.0.0 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
INFO WEBrick 1.3.1
INFO ruby ​​1.9.2 (2010-08-18)
INFO WEBrick::HTTPServer#start: pid=4193 port=3000

The application is running, open the browser at the address and see the test page.

Great, the app is working. But it shows a normal HTML page from the /public/index.html folder. And we want dynamic. We open the second console window (because in the first one we have running the ruby ​​server - WebRick), go to the project folder and type the following command there:

[email protected]:~/ruby/app$ rails generate controller index index
create app/controllers/index_controller.rb
route get "index/index"
invoke erb
create app/views/index
create app/views/index/index.html.erb
invoke test_unit
create test/functional/index_controller_test.rb
invoke helper
create app/helpers/index_helper.rb
invoke test_unit
create test/unit/helpers/index_helper_test.rb
[email protected]:~/ruby/app$

With this we created the Index controller, in it the Index action and the type of this action index.html.erb Do Refresh (F5) in NetBeans and look at our files. Wonderful. Now we need to somehow redirect the route for the main page to the controller action we created. Open the routes file (Configuration/routes.rb) and uncomment the following line there:

# You can have the root of your site routed with "root"
# just remember to delete public/index.html.
root:to => "welcome#index"

But instead of welcome, we also write index. Well, according to Zend Framework, I got used to the fact that the default controller and action are called index. Do not forget to delete (or rename) the public/index.html file).

root:to => "index#index"

We refresh the page in the browser, and we see that our view is now displayed.

index#index

Fine. Now you can code. We go into our newly created controller (Controllers -> index_controller.rb) and write the following action text there:

class IndexController< ApplicationController
def index
@users = User.find(:all)
end
end

Now open the Views/index/index.html.erb view and write the following code there:

index#index


Find me in app/views/index/index.html.erb


<% for user in @users -%>
<%=user.name%>

<% end %>

By doing this, we're telling Rails to iterate through the array of users and display their names. Refresh the page and see the list of users below.

index#index

Find me in app/views/index/index.html.erb

andrey
vasily

Fine! Application created!

Thanks!

If this article helped you, or if you want to support my research and blog, here's the best way to do so:

Today on the internet I found a story about how someone James Fend learned Ruby on Rails for 12 weeks. Below you can read a relatively accurate translation of this story, and hopefully get inspired to learn this great framework (and beautiful language).

Before I get started, I'd like to introduce Josh Crews (http://joshcrews.com) and thank him for encouraging me to start learning Ruby on Rails; without him, his help, and without the hours he spent being my mentor, I wouldn't be writing this today. Thank you.

On January 23, I launched my dream idea, Freelancify.com. Exactly 12 weeks ago, I was a tech entrepreneur spending thousands of dollars to create a decent MVP (Minimum Viable Product) because I lacked the knowledge. One of the reasons (as I thought at the time) was that the training was too difficult for me or would take an excessively long time. I thought (like many others) that programmers (and some do) are born with a set of magical skills in problem solving and math that make them programming geniuses. And exactly 12 weeks ago I made the best decision in a long, really long time. None of my ideas will remain nothing more than an idea. Now I have the opportunity to run production versions, spending money only on hosting and putting in some effort. Today, this skill set is like driving a bunch of tractors during the California gold rush while everyone else is using simple shovels. I suggest everyone learn to write code. Here I would like to add a clarification: earlier, I titled the post “How I learned Rails in 8 weeks”, however, to be precise, given the launch date, it turns out to be 12 weeks. However, after 8 weeks I felt like I knew enough, and the next four weeks were spent more on putting what I had learned to work, rather than learning.

What skills did I have before I started learning Rails?

I was a web designer with a knowledge of HTML and CSS and mainly focused on UI and UX design. The hardest thing I've done with the actual code (other than the HTML) is being able to customize Wordpress. In a word, I had absolutely no idea what an MVC framework was, nor how databases work in general. The design, layout and HTML for Freelancify was created by me in two weeks in June 2011.

Why did I decide to study?

Back in June 2011, when the layout was ready, I started looking for a coder to make the layout work. The layout was almost ready: I ​​had text fields, drop-down menus, forms, buttons, links leading to the right place, and so on. I found a developer, and, in a nutshell, the guy did not suit me. I was left with a bunch of debt and not even close to completing a product. So I got in touch with Josh Crius (I met him at a Ruby on Rails meeting he hosted in Nashville) and met with him to see if I could do something with what I had left of a developer. . Unfortunately, fixing and finalizing the code would take no less time than developing from scratch by a competent programmer. I lost heart, realizing that I could not afford to spend thousands of dollars on development from scratch again. And then Josh said…” Why don't you just learn how to handle Ruby on Rails, this project would be a great way" and then " I can even meet with you twice a week and help you with your studies.". I spent the whole night thinking. My options were: find a comfortable job and pay the bills OR risk it all to learn Rails and end up eating the best ramen in Italy. I decided. Called Josh the next morning. I put everything. I took the money out of my remaining savings and divided it over three months (for an unmarried guy who lives alone and without children, one thousand dollars a month is enough). Time to get to work, now I'm a full time apprentice. Keep in mind: Google search, Stackoverflow, IRC #RubyOnRails and the Rails community will have my back when I get stuck, I'm sure they will be enough.

My next three months - Mission: get an MVP, get enough to work, but not “sucks enough” to leave a terrible first impression.

Weeks 1 - 3

It was perhaps the toughest learning curve, but I did NOT give up.

Walls are made for people who don't really want to leave them.

Setting up a Rails desktop for a complete newbie can be incredibly annoying. Tip #1: Get a Mac. Tip #2: Use Homebrew, RVM, Git and Heroku (that's really all you need to get started). I spent a couple of days installing, then uninstalled everything and reinstalled. It is enough to repeat a few times and you will get used to using the terminal command line (console) and understand why things work the way they work. Then the first thing I did was TryRuby , Rails for Zombies and Rails Tutorial by Michael Hartle. Don't worry about 120% understanding of the material, it won't happen until you start to really learn. I finished the Rails Tutorial and built this Twitter-like app in about a week without really understanding what I did. Later, as I progressed, I began to realize that everything was starting to make sense.

Weeks 3 - 6

With the Twitter app built with the Rails Tutorial, I gained some confidence. The guide didn't make me a developer, but now I know the general steps in building an app, from creating the app itself to installing it on Heroku. All that was in the meantime remained a blur. How can I REALLY start learning now? Working on a real project that means something to me. Josh and I decided that I should work freely on Freelancify and see what I could do. The first thing I did was to take all the HTML from the framework and organize it into views and partials files. I created (scaffolded) template platforms for Users (Users) and Projects (Projects). Then I started learning about my first real gem, Devise. Then, the ability to have relationships, for example each User will have a portfolio. But Users can have multiple portfolios, while each portfolio can belong to only one User. Once you understand how relationships between models work and how to call/display things that belong to something else, life becomes a lot easier. If you are stuck in some part and can not move, skip it, chances are that while you are developing another feature, you will also understand how to implement what you missed.

Weeks 6 - 9

Step by step, I continued to learn by copying and repeating. I could make things work, and then - bam - and I was stuck in a wall and had absolutely no idea what to do next. Going to Stackoverflow, #RubyOnRails IRC chat, RailsCasts, or tugging at Josh, I eventually figured out how to proceed. Do the same thing over and over and you'll learn pretty quickly. Spending annoying hours testing someone's Stackoverflow answer only to find it doesn't work is actually helpful. You understand what not to do. And when you find the answer, you will begin to understand WHY the last one didn't work. Around this time, I began to realize how big the picture of things is, and to really understand WHY everything works exactly the way it works. I felt like an idiot and went back and refactored the code I wrote earlier to make it more efficient. And at some point I reached a stage where everything started to fall into place.

Weeks 9 - 12

I've been in a frenzy of high spirits as I've been building Freelancify into the launch phase. At this stage, I felt like I was healing, bringing functions to life. The last week has been spent debugging various bugs and glitches. This Monday I launched the site. But I'm still far from completing my training... That's it. I have omitted (in the name of brevity) small details and technicalities. However, feel free to ask questions in the comments, I will definitely try to answer. James Fend.

P.S. - Although I was greatly helped by the help of a mentor that I could meet, you can definitely learn Rails without him. Or try to find one for yourself, many Rails developers love to contribute to the community. Look for local conferences and meetings.

This entry is more than two years old (published on January 27, 2012), but, nevertheless, it has not lost its relevance. During this time, James Fend managed to sell Freelancify and invest in a new startup, he wrote about this on February 27, 2013. I think that this article is a great example of how a person can go towards his goal. Just enough to get started. :)

Most likely, you are here because you want to learn the Ruby on Rails framework, but are not quite sure you understand what it is. Well, Rails is just a bunch of Ruby code written to take care of those parts of a web application that you don't really want to think about.

Rails uses, as you may have heard, "agreement over configuration". This means that the creators of Rails have made a lot of decisions for you about how the parts of the application should be structured and how the code should run. You can change this, but it's better if you just go with the flow and work by these rules (especially if you're new).

Think of it like buying a suit: you probably don't care where the thread came from, whose hands made the stitches, what companies delivered the materials to the factory, what the buttons are on it... you trust the tailor with all the details and just want to be able to purchase a suit that fits you well. Rails is your Ruby tailor.

Why not? There are an incredible number of frameworks and technology suites to choose from and, to be honest, they are almost identical in terms of the features they provide. Rails is attractive because it is relatively straightforward and well documented. This framework is used by a huge number of great startups and tech companies, and has a very strong community of developers and students who support it.

Rails lets you build a functioning website in hours, not days or weeks. The "internal" technologies of the industry will likely change over the course of a few years, but Rails offers a great platform for getting the first skills you need to move to the next level.

Because Rails handles a lot of things for you, you can work incredibly fast. You can get a website up and running on the internet (although it won't be particularly pretty) in a couple of minutes. The first time you generate a new project, everything is in place, so all you have to do is start up your local server (by simply typing $ rails server) and you should already be able to see the Rails welcome page. And all you have to do is put together all the necessary pieces that you need to run your complete web application.

It also means that you can immediately start making small changes and see how they affect your application before you have to create complex infrastructure and write tons of code to see the changes made by a single line. Rails will make your life much easier!

Rails also strictly organizes your code using the MVC pattern that you will soon learn and love.

The best way to understand Rails is to start using it, so we'll spend some time watching the video and reading, but then you'll build your first sample application of your own. You may not have an idea of ​​what you are doing, and that's okay, but at the very least you should start to understand what you do NOT know and what you need to pay attention to in order to move forward. A good solution is to write down all the things that baffle you and then find out more about them and keep them in mind until we dive deeper into Rails.

Points for reflection

Try to answer the questions provided. After completing the task, try answering them again.

  • What is Rails?
  • What language is Rails written in?
  • Reminder: What is a gem?
  • What are the seven gems that make up Rails?
  • What is the purpose of the gemfile?
  • What is the command to use to create a new Rails application from the command line?
  • How is a GET request different from a POST request?
  • What is REST?
  • What is a "view"?
  • What is a controller?
  • What is a model?

Tasks:

  1. Check out this basic overview of Rails by Michael Hartle. It demonstrates the creation of a very simple web application.
  2. Read Daniel Kehoe's excellent introductory article What is Ruby on Rails? to understand what we are working with.
  3. Get started with Rails by trying the Rails for Zombies course, which will get you started coding with Rails right in your browser! It goes pretty fast and you may need to watch some videos, but it's worth it.
  4. For a more formal explanation of Model/Views/Controller see this is a short video from Lynda.com
  5. Read Rails for Beginners and try to understand what's going on in the text (you don't need to create this test application, but it's worth reading the process of creating one. You'll be writing your own pretty soon). By the end, you will most likely get confused, but don't worry, this is normal. You will have no problem understanding what is described by the time you complete the Rails course later in our curriculum. Rusrails offers one of the best Rails documentation in Russian, so it's good to start getting familiar with its content.

Additional Resources

Build real applications using Ruby on Rails. You may have tried Ruby on Rails but found it too complicated and feel like you need a more complete introduction. Perhaps your boss or client has thrown you in the deep end with a Ruby on Rails project and you need to learn about Rails quickly? Or maybe you've decided you want to add web development and Ruby on Rails to your resume. If so, you are at the right place. This course will teach you how to build web applications with Ruby on Rails.


Why Ruby on Rails?

Ruby on Rails is a fast and efficient way to develop web applications. It simplifies common repetitive tasks that take a long time to create in other languages. It is much easier to get a high quality product completed in Ruby on Rails than in other languages.

Because the framework is mature, there are a ton of open source projects/code that you can use that are extremely powerful and really give you an edge in building robust web applications.

In addition, it uses the Ruby programming language. Ruby code reads like English, which makes it much easier to understand if you're just starting to code. As a dynamically typed language, Ruby doesn't have all of the hard and fast rules that other languages ​​make and is similar to a spoken language in many ways. This gives you the flexibility to solve problems in a more human way than other programming languages.

What is covered?

Some of the features covered by the course include...

Git Basics, Rails core "7 methods" and how they perform "CRUD", Rails Routing, Strong Parameters, Custom Callbacks, Custom Validation, Partials,

Bootstrap 4, Rails Generators, User Authorization, User Authentication, Content Management, Deployment, Database Loading, Send/Receive Email Using Rails App, Sidekiq Setup, Redis Setup on Heroku and Private Server, Template Installation, Custom Validation Messages, adding Assets to the Rails Pipeline, uploading images to your own server, uploading to AWS, adding WYSIWYG - what you see is what you get from the editor and more!

Why enrolling in this course is the best decision you can make.

These courses use simple examples to complete complex tasks. The goal is to make you understand exactly what you are doing and the reasons why, rather than typing in code you don't understand. No code is obscured as it is important for you to understand what each line does.

After completing this course, you will have the necessary skills to create your own web applications using Ruby on Rails.

The sooner you sign up for this course, the sooner you will have the skills and knowledge you need to increase your experience. Ruby on Rails developers are in high demand! Why not start working on Ruby on Rails today?