Your local zoo has hired you to build a web-based application (app). Based on the zoo's specifications, the app should catalogue every animal at the zoo.
Note: The app will not persist data nor have a login system; we will get to both shortly!
##User Stories The User should be able to...
- Expect RESTful routing
- See an Index of the existing animals on both the root page and
/animals
- Animals should have a name, photo, and bio. (For now we will not worry about hosting our own photos; you should link to external photos)
- Next to each Animal have a link to the edit page & a delete button
- Create a new Animal
- Page should be accessible via a persistent link in their nav bar
- The route for this and all other pages should be restful ie
/animals/new
- Post to animals#create then redirect to the index page
- Delete an Animal
- Redirect to the index page
- Run
rails new RailsZoo
to settup your app using postgresql as the default database - Name your databases in config/database.yml and then run
rake db:create
- Write your own custom routes, if you need a good reference refer to the routes guide in the Rails Docs. I.e. * get '/animals/new', to: 'animals#new' * post '/animals', to: 'animals#create' * etc.
- Create a contoller you'll need
- Create a view that your controller renders
- Create a model for you animals that will store the data and behavior for them. Note: you will create an Animal class with class methods. It is also recommended you seed your site with some initial animal data. Here's a good starting point:
#animal.rb file in models folder
class Animal
#seed animals
@@animals = ["lions", "tigers", "bears", "elephants", "dolphins"]
def self.all
@@animals
end
def self.create(animal)
@@animals.push(animal)
end
end
And of course, you can always look back at notes from this afternoon to help you with properly configuring your routing, controllers and views.
-
Add routes and methods to allows the user to update an existing animal
-
Include your own custom styling, bootstrap or another CSS framework in your application and style your blog.
-
Include flash messages to display success and error messages for when an animal is created or deleted