forked from zenspider/seattlerailsbridge
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
67 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,73 +1,89 @@ | ||
--- | ||
goal_title: CRUD with Scaffolding | ||
goal: | | ||
At the core, most database driven web sites are the same. They need to | ||
store records and provide a way to do the following: | ||
* **C**reate new records in the database | ||
* **R**ead or show the records in the database | ||
* **U**pdate existing records | ||
* **D**estroy or delete records | ||
Because these 4 actions (CRUD) are so common rails includes the | ||
scaffold command to make creating them easier. | ||
steps: | | ||
* `rails server` | ||
* Point your browser to [http://localhost:3000/topics http://localhost:3000/topics] | ||
* Run `rails server` in your terminal. | ||
* Point your browser to [http://localhost:3000/topics](http://localhost:3000/topics) | ||
* You should see a page listing topics that looks something like this: | ||
[[File:Seattle_topic_list_page.png]] | ||
![topic list page](/img/Seattle_topic_list_page.png) | ||
* Click on "New Topic" | ||
* Fill in the form to and click "Create Topic" | ||
* You should see a confirmation page like this: | ||
[[File:Seattle_topic_created.png]] | ||
![topic created](/img/Seattle_topic_created.png) | ||
* Click on 'back' | ||
* Click on "back" | ||
* You should see the topic list again, this time with your new topic listed | ||
[[File:Seattle_list_with_topic.png]] | ||
![list with topic](/img/Seattle_list_with_topic.png) | ||
* Try the 'show', 'edit', and 'destroy' links to see what they do | ||
* You've created a basic database driven web site, congrats! | ||
goal: | | ||
At the core, most database driven web sites are the same. They need to | ||
store records and provide a way to do the following: | ||
* '''C'''reate new records in the database | ||
* '''R'''ead or show the records in the database | ||
* '''U'''pdate existing records | ||
* '''D'''estroy or delete records | ||
Because these 4 actions (CRUD) are so common rails includes the | ||
scaffold command to make creating them easier. | ||
goal_title: CRUD with Scaffolding | ||
explanation: | | ||
* How did all those pages get created and hooked together? | ||
** The rails scaffold did it for you. | ||
How did all those pages get created and hooked together? The rails scaffold did it for you. | ||
Let's take a closer look at some of the files rails created: | ||
* app/models/topic.rb | ||
** This file contains code for our topic model. If you look at it its nearly blank. Creating, reading, updating, and deleting records is built into rails. | ||
** If you've written HTML before many lines in the views should look familiar. Rails views are HTML with some extra code added to display data from the database. | ||
* app/views/topics | ||
** This folder contains all the views for our topics model. This is where the code for the forms you used above is stored. Rails created all of these pages as part of the scaffold. | ||
* app/views/topics/index.html.erb | ||
** This is the code for the page that lists all the topics. | ||
** Index is the name given to the "default" page for a website or a section of a website. When you navigate to http://localhost:3000/topics the topics index page is what is sent to your computer. | ||
* app/views/topics/show.html.erb | ||
** This the page you get when you click the "show" link on the "Listing topics" page. | ||
* app/views/topics/new.html.erb | ||
** This is the page you get when you click on "New Topic". | ||
* app/views/topics/edit.html.erb | ||
** This is the page you get when you click on "Edit" | ||
* app/views/topics/_form.html.erb | ||
** You may have noticed that the page for new topics and the page to edit topics looked similar. That's because they both use the code from this file to show a form. This file is called a partial since it only contains code for part of a page. Partials always have filenames starting with an underscore character. | ||
* Challenge question: Can you find the line of code in new.html.erb and edit.html.erb that makes the form partial appear? | ||
* `app/models/topic.rb` | ||
* This file contains code for our topic model. If you look at it | ||
its nearly blank. Creating, reading, updating, and deleting | ||
records is built into rails. | ||
* If you've written HTML before many lines in the views should | ||
look familiar. Rails views are HTML with some extra code added | ||
to display data from the database. | ||
* `app/views/topics` | ||
* This folder contains all the views for our topics model. This is | ||
where the code for the forms you used above is stored. Rails | ||
created all of these pages as part of the scaffold. | ||
* `app/views/topics/index.html.erb` | ||
* This is the code for the page that lists all the topics. | ||
* Index is the name given to the "default" page for a website or a | ||
section of a website. When you navigate to | ||
http://localhost:3000/topics the topics index page is what is | ||
sent to your computer. | ||
* `app/views/topics/show.html.erb` | ||
* This the page you get when you click the "show" link on the | ||
"Listing topics" page. | ||
* `app/views/topics/new.html.erb` | ||
* This is the page you get when you click on "New Topic". | ||
* `app/views/topics/edit.html.erb` | ||
* This is the page you get when you click on "Edit" | ||
* `app/views/topics/_form.html.erb` | ||
* You may have noticed that the page for new topics and the page | ||
to edit topics looked similar. That's because they both use the | ||
code from this file to show a form. This file is called a | ||
partial since it only contains code for part of a page. Partials | ||
always have filenames starting with an underscore character. | ||
* Challenge question: Can you find the line of code in new.html.erb | ||
and edit.html.erb that makes the form partial appear? | ||
* app/controllers/topics_controller.rb | ||
** This is the controller file that rails created as part of the scaffold | ||
** If you look you'll see a method (a line beginning with <code>def</code>) for each of the views listed above (except _form.html.erb) | ||
* This is the controller file that rails created as part of the scaffold | ||
* If you look you'll see a method (a line beginning with | ||
<code>def</code>) for each of the views listed above (except | ||
_form.html.erb) |