-
Notifications
You must be signed in to change notification settings - Fork 2
Rails program runs with unexpected results
When it comes to Rails, try to follow the flow of your program.
Most http requests follow this flow:
-
The browser sends the request to the server (if you're issue is happening while developing, then the browser is likely sending the request to IP Address 127.0.0.1 (localhost), TCP Port 3000.
-
Rails looks up the request in its Routing table
-
Rails sends the request on to the appropriate Controller
-
Rails invokes the appropriate Action (aka method) in the Controller
-
Your Controller Method uses Model(s)
-
Your Models communicate with the Database
-
Your Controller Method renders a View and Layout
-
The response is send back to the browser
GET - if the URL was entered into a browser's location bar and enter was pressed, or if a regular link was clicked
POST - if a form submit button was clicked to create a new record
PUT & PATCH - if a form submit button was clicked to update an existing record
DELETE - if a link with the method set to delete
For GET requests: the URL will be in the browser's location bar.
For POST / PUT / PATCH requests: you can see the URL by using debugging tools to inspect the <form> tag. Within the <form> form tag is an action attribute. This will be set to the URL or PATH.
For DELETE requests, inspect the delete link using debugging tools and look at the href attribute.
A URL is made up of several parts:
-
Protocol:
httporhttps -
Hostname:
localhost -
Port number:
80or3000(sometimes this isn't visible) -
Path: the segment between the Hostname/Post Number up until either the end of the URL, or until the first
?(whatever comes first) -
Parameters: everything that follows the
?(not necessarily present)
The segment that follows the hostname at the 2nd half of the URL. That is the path
- What is the URL?
- What type of request (get, post, etc)?
Armed with this information, take a look at your routes using:
rails routes
on the command line.
You should see something like this:
TODO
This is a living document. If you have anything to add, change or remove, please let us know. Or better yet, as it's a wiki, make the change yourself!