Table of Content
Building the photo controller and view
We want RESTful URLs for our photo resource. Here is the
It is time to create the contorller.
Let’s try the function in browser with the following steps.
- In terminal, in the current project, run
http://0.0.0.0:3000/photos/newin web browser.
- Select an image file and put in the title.
- Click the ‘Upload Photo’ button.
- Now we should see an error of
- If we check the URL, it is redirected to the photo showing URL with the newly created photo ID.
- This is normal because we haven’t implemented the
showmethod in controller yet.
Then we add the show feature
And its related view:
Since the edit form shares the same code from the create form, we will extract the form into a common file.
Move the entire
form_for block to a new file:
Optionally we may want to let site admin edit the photo from the user interface, we can do that by adding a link to the edit path in the
update controller method in the
Let’s try the function in browser and we should be able to create and edit photos. Here is a screenshot of the editing screen:
What’s next? We’re going to take a look at “Using partial file”.