Mysterious X Project

It is said that one day in a dream I was on China's Got Talent.

Zhou Libo: What's your name?
Me: My name is XXX, from Taipei, Taiwan.
Zhou Libo: What is your occupation?
Me: I am an amateur small code farmer engaged in web development.
Zhou Libo: Wow, the kind that specializes in writing code?
Me: Yes, yes, I will often write code from my home to the company, and directly write it until the morning of tomorrow morning.
Zhou Libo: How many lines of code are there at a time?
Me: It's probably less than 4000 lines of code at a time.
Zhou Libo: Do ​​you use Ruby or PHP?
me: PHP.
Zhou Libo: . . . . . . . . Very hard!
Me: I write code in the company for about twenty-two or three days a month, and I am very lonely. Even when I was at my loneliest, I listened to the music I liked, and spent every day and every moment like this.
Zhou Libo: What kind of feelings do you think people have when they are on the way?
Me: I just feel that when I am coding, when I look down, what I see is my code, and when I look up, what I see is my dream.
Zhou Libo: Yo oh, oops, very wet person feeling, when he bows his head is his code, when he looks up is your dream, so what show are you going to perform?
Me: I… bring a song today, a song I often sing while programming. Aoi-sensei's second dream.
Zhou Libo: . . . . . . . . . . . . . Start your show.
Moderator: In more than 4,000 lines of code, what kind of sound will appear? to comfort himself? Video link

However , at this moment,

suddenly the phone rang (click to listen)

The ringing of my phone woke me up at an unusual time, and half-awake I picked up the call I shouldn't have answered. . .

Me: Um, who are you?
? : waist hungry Sanning six
I :. . . who?
? : waist-hungry-shen-ning-six
I : Uh. . . Excuse me... Can you speak Mandarin?
? : Hello sir, we are the Ministry of Railways here.
Me: (thinking to myself) Damn, when I went to China's Got Talent show last time, I was arrested for evading fares by taking a ride. . .
Me: Um, what's the matter?
12306: Hello sir, I don't know if you have the will to build a website. There are all kinds of chaos on Sina Weibo and Twitter. At present, the unit is secretly recruiting people to develop a new Weibo.
me: uh. . . This is brave. . . But how can you find me. . . I don't understand JSP's!
12306: After numerous meetings and consideration, the leader decided to use Rails, a technology worthy of the Ministry of Railways' name, to develop our new Weibo. We found you through the Code Farmers Association.
me: uh. . . Coders Association?
12306: An association is located in District 51 similar to the United States, a mysterious special district.
Me: Oh. . . How did you choose me?
12306: We found that your usual dreams are related to programming. I believe you are the right person. Some people will take you to District 51 for coding later.
Me : Khan. . . Can I try this? I can't seem to do it. . .

Suddenly, with a thud, a few big men from Shandong fell from the sky and took me away. When I woke up, I didn't know where I was. It seemed to be District 51. . .
You can only program here every day and every moment, otherwise there will be a bunch of beauties rushing out to hit you with XX, or forcing you to use JAVA/C++ programming, it's terrible, I'll do it better!

This is my first day in District 51. I want to record all my work. . .

Uh, this is a very challenging project. Although I have no experience in PHP development for 2 years, nor have I worked on JSP in my graduation project, and my ability to convert complex to simplified is only limited to traditional to simplified, I still If I want to try this huge challenge, although hundreds of millions of HTTP Requests, I will go. . .
Mysterious X project
Create a project

(too lazy to listen to my nonsense, just look at what commands I entered in this section => here)

This mysterious X project will eventually have users, Weibo, with complete user login and verification functions, we will start from Create a static page to get started. As simple as it sounds, creating static pages is a perfect start to your application! Although Rails is designed to create dynamic websites with databases, it's also very aggressive for generating static pages mixed with small amounts of dynamic content. However, for the whole project, we will use a good test suite for development, and tell you how to use spork+guard to speed up the test operation. For the whole project, we will use the most prosperous RSpec with some other Gems for testing.

If you're new to Ruby, or a friend who's just learning Ruby, don't get too caught up in the details, how this works. . . You didn't watch the movie so carefully when you were a child. When you really have some "practical" experience, it's not too late to go back and savor it. Also, later I'll touch on some basic Ruby knowledge you'll need.

Ok, let's get started, first of all I'm using RVM, I'll create a new gemset for the project to use:

rvm gemset create rails-x

You can call it rails-x, my-ex-girlfriend, and you'll be happy!

Then install the latest version of Rails 3.2.3:

gem install rails -v 3.2.3

After the installation is complete, create a new project. Since we are using RSpec, we add the --skip-test-unit parameter, and we also need to install some special Gems, so skip the bundle step first --skip-bundle :

rails new x_weibo --skip-test-unit --skip-bundle

What is the bundle command? Didn't you see my 000-003 series? It doesn't matter, because I didn't say 000-003, the bundle is actually to help you install those gems that should be installed, don't worry, they won't take you to the labor camp.

Next let's install RSpec and some gems that will be used, we will install rspec-rails 2.9.0, capybara 1.1.2, and for the production database we will use PostgreSQL to deploy to Heroku.

Heroku? What is this? Well, you know that every year Ruby has a Hero Award, it's a cloud service platform so slow that even a Ruby Hero would cry, making it easy to push your Rails applications to the cloud. . . Why is it so slow? Because it is very useful for people like us who are still 9XX hours away from learning Rails, and let you play subordinates without money (friendly reminder: in life, those who don’t have money are often the most expensive). Ha ha! Go to register an account first, Heroku registration press me press me press me

First you need to install PostgreSQL, please read this article: Install PostgreSQL for windows, ubuntu, Mac. However we will use the same database PostgreSQL for development and production mode, let's change the Gemfile:

source 'https://rubygems.org'

gem 'rails', '3.2.3'
gem 'pg', '0.12.
gem 'bootstrap-sass', '2.0.0'

group :development, :test do
  gem 'rspec-rails', '2.9.0'
end

# Gems used only for assets and not required
# in production environments by default.
group : assets do
  gem 'sass-rails', '3.2.4'
  gem 'coffee-rails', '3.2.2'
  gem 'uglifier', '1.2.3'
end

gem 'jquery-rails', '2.0.0'

group :test do
  gem 'capybara', '1.1.2'
end

rspec-rails in dev mode gives us access to RSpec generators, while in test mode group lets us write tests. We don't need to install the RSpec Gem as with RSpec alone, because it is already included in the rspec-rails dependencies. In the test module we install capybara, a suite that simulates user behavior using an English-like syntax.

Also we need to set config/database.yml where username is your username, for example my username is Mac, please see Railscast 342 Migrating to PostgreSQL, please watch this video first to see how it is set, The video is about 8 minutes, only 8 minutes! Otherwise, you may encounter many problems. Of course, you can use SQLite3, but the predecessors said that it is the best practice to use the same database in the development and production environment, and I wear different underwear every day.

Don't worry, the configuration is unsuccessful. Feel free to ask. People in Ruby-china are willing to answer for you, but remember to provide enough information

. Does anyone know how to put it on?

It's like saying,

I've been with so-and-so, and I've failed, does anyone know what to do?

Who knows when you talk like this, the details are the details, the key is the details, you have to provide more details. . .

Well, look back at how database.yml is configured, you can refer to my database.yml:

development:
  adapter: postgresql
  encoding: unicode
  database: x_weibo_dev
  pool: 5
  username: Mac
  password:

test:
  adapter: postgresql
  encoding: unicode
  database : x_weibo_test
  pool: 5
  username: Mac
  password:

production:
  adapter: postgresql
  encoding: unicode
  database: x_weibo
  pool: 5
  username: Mac
  password:

After changing the Gemfile and configuring the database, let's

bundle install --binstubs --without production

, this Will help us install all the gems described in the Gemfile. The --binstubs option is for easier access to some executable files later. --without production Let's not generate gems in production mode during development.

Note that the first bundle will remember the options you entered, and after that, just use a simple bundle command.

By the way, you just mentioned that --binstubs is more convenient, what is it? Well, since you asked the question sincerely, I will tell you graciously, the general invocation of the rake command is like this:

bundle exec rspec but hit --binstubs it will put rake in a bin directory for us , so that we can call it like this: bin/rspec or even rspec, a few words less, programmers are lazy.

OK, run it out:

After bundle install --binstubs --without production

, you will see:

Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.

Yay! YEAH! Let's configure Rails to use RSpec instead of the default Test::Unit:

rails generate rspec:install

OK, it's that easy. Simple........

Next, let's put the project files on Github for version management. First, you need to apply for a Github account and install Git on your computer. Please follow the steps in this article to set up Github in order. If you If you are not familiar with Git, you can take a look at this simple guide to Git, are you really still worried? Well, then you can read Git Magic or Pro Git, two free books, both in Chinese!

Well, after we have Git and Github, let's change .gitignore, this file can filter out some unnecessary files and prevent them from uploading to Github. Open .gitignore and add:

*.rbc
*.sassc
.sass-cache
capybara-*.html
.rspec
/.bundle
/vendor/bundle
/log/*
/tmp/*
/db/*.sqlite3
/public/system/*
/coverage/
/spec/tmp/*
**.orig
rerun.txt
pickle-email-*.html
doc/
*.swp
*~
.project
.DS_Store
bundler_stubs/

or Others, such as important reports (do not open for mom), mock exam questions for the college entrance examination (do not read important), etc., are directories that you do not want others to see.

Oh, very good, you have passed the hardest level of learning Rails, configuring the development environment! ! ! ! ! ! ! !

However, I suggest you change the README.rdoc in the directory to README.md

mv README.rdoc README.md

README.md can put something like:

# Mom, I'm starting to learn Rails!
Trying to learn Rails!!!

Next let's host these files on Github and Heroku.

git init
git add .
git commit -m 'Init Commit'

go to Github to create a new repo -> or click here directly

git remote add origin [email protected]:<username>/your-repo-name.git
git push -u origin master

Next is to add a heroku domain name (if you haven't set up Heroku, here are the steps)

heroku How to push and upload to Github after create --stack cedar
git push heroku master : How to push and upload to Heroku after git push: git push heroku , etc. What about accelerated testing? Spork and Guard, you can refer to this: Rails 3.2.3 Using Spork + Guard + RSpec + Capybara and attach an article on how to configure Windows/Linux/MacOS Sublime Text2 editor, here are three Michael Hartl teach you how to configure the environment , etc. , why not use VIM and Emacs? Well, those people will use it themselves, I said it for you who are just getting started, dear. Installation alone has taken so long, let's actually start creating static pages! The Rails train is about to start, ooh--oh-oh-oh-oh-oh-oh-- why did the onomatopoeia become oh-oh-oh this time? Because there was a Shandong man whose finger was caught by the door. . . God bless him! 950 hours to learn Rails. .



























Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326604696&siteId=291194637