所需积分/C币:17 2016-03-07 09:50:49 3.36MB PDF

A step by step guide to learn Ruby on Rails 5.0. It includes a basic tutorial for Ruby 2.3 and is written for programmers who know at least one other programming language and are familiar with HTML. It covers Active Record, Scaffolding, REST, Routing, Bundler, Test Driven Development, Cookies, Sessi
PREFACE Don't let people fool you into believing that ruby on rails is easy to learn. It is not! It's probably the best and most effective framework to develop web applications but it is hard to understand in the beginning. The worst mistake of all is to not learn ruby before diving into Ruby on Rails. To avoid it this book starts with the basics of Ruby. You will not become a ruby guru after reading it but you'll understand the basic ideas and that important I wrote this book for developers who learn best by following clean examples. i dont like he idea of coding one big single application throughout a book but prefer smaller stand- alone code examples. Therefore you can skip a couple of pages or even complete chapters without losing context Shameless plug: Please contact me by e-mail to stefan wintermeyer@amoomade if you need Ruby on Rails consulting or training Have fun with Ruby on rails Stefan wintermeyer Ps:IpostupdatesaboutthisbookandRailsingeneralat Stefan Wintermeyer RUBY BASICS Introduction This book requires basic knowledge of HTML, plus the reader -you, in other words should also have a basic understanding of programming. The beginning of this chapter is going to be a bit boring. Bcar with me. It's worth it It is easy to program in Ruby, but ruby is not a simple language.” n Yukihiro matsumoto This chapter is a tightrope walk between oversimplification and a degree of detail that is unnecessary for a Rails newbie. After all, the objective is not becoming a Ruby guru, but understanding Ruby on Rails. I am going to elaborate on the most important points. The rest is then up to you. If you would like to know more about Ruby, then i recommend the book"The Ruby Programming Language"by David Flanagan and Yukihiro Matsumoto The command ruby -v will print the current running Ruby version sp ruby -V ruby2.3.p0(2015-12-25 revision53290)[X8664- darwin15] $ Hello World Ruby is a scripting language so it is not compiled and then executed but read by an interpreter and then processed line by line A simple ruby program hello-world. rb consist of the following line Listing 1. hello-world rb puts 'Hello World Use your favorite editor to open a new file with the filename hello-wor ld. rb and insert the above line into it. You can then execute this Ruby program in the command line as follows s ruby hello-world rb Hello wor ld i $ a program line in a Ruby program does not have to end with a semicolon. The ruby interpreter is even so intelligent that it recognizes if a program line was split over two on more lines for the sake of readability. I will spare you the corresponding examples and am only mentioning this so you don't say or think later, is it okay like this? Indenting code is also not necessary. But it does make it much easier to read for human beings puts and print If you go looking for examples on Ruby on the Internet, you will find two typical ways of printing text on the screen puts prints a string, followed by a newline print prints a string(without new line) Example program(an extension of the program hello-world. rb) Listing 2. hello-world rb puts 'Hello world puts puts Zzz print Hello world! print puts ZZz On the screen, you will see this s ruby hello-world rb Hello world ZZZ Hello world! zzz Comments A comment in a Ruby program starts with a #-sign and ends with a newline. As an example, i can add a comment to the hello-world. rb above Listing 3. hello-world rb Program for displaying " Hello world! by stefan wintermeyer puts Hello world! A comment can also follow a program line Listing 4. hello-world rb Program for displaying "Hello World! by Stefan Wintermeyer puts Hello world! output A #-sign within strings in inverted commas is not treated as the start of a comment Example program Listing 5. hello-world rb Example program by stefan Wintermeyer puts Hello World! puts'并并并并H计并并H计并 puts puts'1并2#34并5#6#1# Comment on this Help via ri When programming, you do not always have a Ruby handbook available. Fortunately, the Ruby developers thought of this and provided a built-in help feature in form of the program ri (of course only if you have installed the documentation which is the default This is a typical chicken and egg situation. How can I explain the ruby help feature, if we are only just getting started with Ruby? So I am going to jump ahead a little and show you now you can search for information on the class String s ri string If we are looking for information on a specific method (chicken-egg! ), then we can also useri. Let's take gsub as an example. This is a method for replacing parts of a String (that is useful now and again) s ri String size = string size (from ruby site str size integer Returns the character length of str The program ri always prints the output in the pager program defined by the shell (for example less). You can also use the command option-t to output everything directly to STDOUT irb stands for Interactive Ruby and is a kind of sandbox where you can play around with Ruby at your leisure. irb is launched by entering irb on the shell and ends if you enter exit An example is worth a thousand words s irb > puts Hello World! I Hello world! nil exit $ I use IRB. conf[: PROMPT_MODE]=: SIMPLE in my .irbrc config file to generate shorter irb output. You can do the same by using irb --simple-prompt


评论 下载该资源后可以进行评论 2

paul712 还可以,谢谢分享
aunmro 感觉还行,只是感觉用着不是特别顺手.

关注 私信 TA的资源