Last active
January 4, 2016 07:29
-
-
Save nathantross/8588957 to your computer and use it in GitHub Desktop.
Notes from Rails Review - Jan 23
This file contains hidden or 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
| # app/controllers/site_controller.rb | |
| class SiteController < ApplicationController | |
| def index | |
| end | |
| def contact | |
| end | |
| def about | |
| end | |
| end | |
| # app/controllers/animal_controller.rb | |
| class AnimalsController < ApplicationController | |
| def index | |
| @animals = Animal.all | |
| end | |
| def new | |
| @animal = Animal.new | |
| end | |
| def create | |
| new_animal = params.require(:animal).permit(:name, :species, :age, :nickname, :status, :description) | |
| animal = Animal.create(new_animal) | |
| redirect_to animal_path(animal.id) | |
| end | |
| def show | |
| id = params[:id] | |
| @animal = Animal.find(id) | |
| end | |
| def edit | |
| id = params[:id] | |
| @animal = Animal.find(id) | |
| end | |
| def update | |
| id = params[:id] | |
| updated_info = params.require(:animal).permit(:name, :species, :age, :nickname, :status, :description) | |
| @animal = Animal.find(id) | |
| @animal.update_attributes(updated_info) | |
| redirect_to animal_path(@animal.id) | |
| end | |
| end | |
| # config/routes.rb | |
| # config/routes.rb | |
| ReviewApp::Application.routes.draw do | |
| # Site Controller | |
| root to: "site#index" | |
| get "/contact", to: "site#contact" | |
| get "/about", to: "site#about" | |
| # Animal Controller | |
| get "/animals", to: "animals#index", as: :animals | |
| get "/animals/new", to: "animals#new", as: :new_animal | |
| get "/animals/:id", to: "animals#show", as: :animal | |
| get "/animals/:id/edit", to: "animals#edit", as: :edit_animal | |
| post "/animals", to: "animals#create" | |
| patch "/animals/:id", to: "animals#update" | |
| end | |
| # app/views/site/index.html.erb | |
| <h1> Welcome to the Zoooo </h1> | |
| # app/views/site/contact.html.erb | |
| Working on it | |
| # app/views/site/about.html.erb | |
| we're not "that interesting yet | |
| ########## Animal Views | |
| #_animal.html.erb | |
| <div> | |
| <div> <%= animal.nickname %> </div> | |
| <div> <%= animal.status %> </div> | |
| <div> | |
| Name: <%= animal.name %>, Species <%= animal.species %> | |
| </div> | |
| <div> | |
| Description:<br> | |
| <p> | |
| <%= animal.description %> | |
| </p> | |
| </div> | |
| </div> | |
| # app/views/animals/index.html.erb | |
| <%= render partial: :animal, collection: @animals %> | |
| # app/views/animals/new.html.erb | |
| <%= form_for @animal do |f|%> | |
| <%= f.text_field :name, placeholder: "enter name" %> <br> | |
| <!-- <input type="text" name="animal[species]" placeholder="enter species"> --> | |
| <%= f.text_field :species, placeholder: "enter species" %> <br> | |
| <%= f.text_field :nickname, placeholder: "enter nickname" %> <br> | |
| <%= f.text_field :age, placeholder: "enter age" %> <br> | |
| <div> | |
| On Display: <%= f.radio_button :status, "display" %> <br> | |
| On Vaaction: <%= f.radio_button :status, "vaction" %> <br> | |
| On Lease: <%= f.radio_button :status, "lease" %> | |
| </div> | |
| <%= f.text_area :description, placeholder: "Describe teh animal" %> <br> | |
| <%= f.submit class: "btn btn-primary" %> | |
| <% end %> | |
| # app/views/animals/show.html.erb | |
| <div> | |
| <div> <%= @animal.nickname %> </div> | |
| <div> <%= @animal.status %> </div> | |
| <div> | |
| Name: <%= @animal.name %>, Species <%= @animal.species %> | |
| </div> | |
| <div> | |
| Description:<br> | |
| <p> | |
| <%= @animal.description %> | |
| </p> | |
| </div> | |
| </div> | |
| # app/views/animals/edit.html.erb | |
| <%= form_for @animal do |f|%> | |
| <%= f.text_field :name, placeholder: "enter name" %> <br> | |
| <!-- <input type="text" name="animal[species]" placeholder="enter species"> --> | |
| <%= f.text_field :species, placeholder: "enter species" %> <br> | |
| <%= f.text_field :nickname, placeholder: "enter nickname" %> <br> | |
| <%= f.text_field :age, placeholder: "enter age" %> <br> | |
| <div> | |
| On Display: <%= f.radio_button :status, "display" %> <br> | |
| On Vaaction: <%= f.radio_button :status, "vaction" %> <br> | |
| On Lease: <%= f.radio_button :status, "lease" %> | |
| </div> | |
| <%= f.text_area :description, placeholder: "Describe teh animal" %> <br> | |
| <%= f.submit %> | |
| <% end %> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment