You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: sites/zh-tw/intro-to-rails/add_the_project_to_a_git_repo.step
+19-19
Original file line number
Diff line number
Diff line change
@@ -1,56 +1,56 @@
1
1
2
2
goals do
3
-
goal "Create a local git repository"
4
-
goal "Add all our files to the git repository"
3
+
goal "建一個本地的 git repository(倉庫)"
4
+
goal "把所有檔案加入 git repository"
5
5
6
-
message "In order to publish our application, we need to add our application and any changes we make over time to a \"revision control system\". In our case we're going to use *git* because it is (relatively) easy and it is what our app server, *Heroku*, uses."
message "It doesn't look like anything really happened, but 'git init' initialized its repository (repo) in a hidden directory called `.git`. You can see this by typing `ls -a` (list all files)."
message "`git commit` tells git to actually _do_ all things you've said you wanted to do."
46
-
message "This is done in two steps so you can group multiple changes together."
47
-
message "`-m \"Added all the things\"` is just a shortcut to say what your commit message is. You can skip that part and git will bring up an editor to fill out a more detailed message."
message "`-m \"Added all the things\"` 這個捷徑讓你可以直接寫下 commit message。你可以省略之,這樣子 git 會打開一個編輯器請你填寫詳細的 commit message。"
48
48
end
49
49
end
50
50
51
51
explanation do
52
52
message <<-MARKDOWN
53
-
By checking your application into git now, you're creating a record of your starting point. Whenever you make a change during today's workshop, we'll add it to git before moving on. This way, if anything ever breaks, or you make a change you don't like, you can use git as an all-powerful "undo" technique. But that only works when you remember to commit early and often!
* `generate scaffold` tells rails to create everything necessary to get up and running with topics.
18
-
* `topic` tells rails the name of the new model.
19
-
* `title:string` says that topics have a title, which is a "string".
20
-
* `description:text` says that topics have a description which is a "text". (What's the difference between "string" and "text"? Basically "text" is for strings that might be very long.)
message "If you want, take some time to poke around the files listed in this step. You can learn about them in the [Rails Architecture](rails_architecture) page."
Here, `rake db:migrate` is a task provided by the Rails framework. It uses the migration file we just created (`db/migrate/201xxxxxxxxxxx_create_topics.rb`) to change the database. Database migration files can be crucial to code collaboration.
* For all the Models we create in RailsBridge, Model objects have a corresponding record in the the database. The name of the table in the database is the plural version of the Model's class name. For example, if the Model is called 'Duck', it will automatically query or write to the 'ducks' table in the database.
26
-
* Methods internal to Rails make it easy to automatically write records to the the database and query the database to get the records again later.
27
-
* The Model is a bridge between the database and your application's code.
25
+
* 我們在 RailsBridge 建立的 Model,其每一個 Model object 都在資料庫裡面有對應的資料。資料庫裡面的表格(table)是 Model 的 class name 的複數形。例如,如果 Model 叫做 'Duck',就會自動去資料庫讀寫 'ducks' 這個表格。
* The View generates the HTML that will be displayed in the browser.
33
-
* View files are written in ERB, a templating language. It contains HTML with Ruby code embedded in it. The ruby variables in the view stand as placeholders for content that will be filled in when a user requests the page.
34
-
* (There are several other templating languages available, but in RailsBridge we always stick to ERB.)
When Models, Views and Controllers are all put together, they follow a pattern: Given a URL, Rails will look up which Controller method (also called an "Action") to use. The Controller Action will use methods in a corresponding Model. The Model will need to read or write to the database, and return an object containing that data to the Controller. The Controller will take that object and pass it to the View. (Actions normally have a corresponding View file, and Rails will automatically find and use that file.)
45
+
當我們把 Models、Views、Controllers 放在一起的時候,他們會遵循以下的模式:
46
46
47
-
Models, Views and Controllers each have specific jobs. Separating responsibilities like this make it easier to develop, especially as it gets bigger. (When each file has a clear responsibility it's easier to fix problems and add new features.)
0 commit comments