Created
December 7, 2014 05:16
-
-
Save zhew117/be4d0d048e126a94d209 to your computer and use it in GitHub Desktop.
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
Zombie.find(1) | |
Zombie.create | |
Zombie.last | |
Zombie.order(:name) | |
Zombie.find(3).destroy | |
class Zombie <ActiveRecord::Base | |
validates :name, presence: true, uniqueness: true | |
validates_uniqueness_of :name | |
validates_presence_of :name | |
end | |
class Weapon < ActiveRecord::Base | |
belongs_to :zombie | |
end | |
z = Zombie.find(1) | |
z.weapons | |
<h1><%= zombie.name %></h1> | |
<p> | |
<%= zombie.graveyard %> | |
</p> | |
<p> | |
<%= link_to zombie.name, zombie %> | |
</p> | |
<ul> | |
<% zombies.each do |zombie| %> | |
<li><%= zombie.name %></li> | |
<% end %> | |
</ul> | |
<ul> | |
<% zombies.each do |zombie| %> | |
<li> | |
<%= zombie.name %> | |
<% if zombie.tweets.size > 1 %> | |
SMART ZOMBIE | |
<% end %> | |
</li> | |
<% end %> | |
</ul> | |
<ul> | |
<% zombies.each do |zombie| %> | |
<li> | |
<%= link_to zombie.name, edit_zombie_path(zombie) %> | |
</li> | |
<% end %> | |
</ul> | |
def show | |
@zombie = Zombie.find(params[:id]) | |
end | |
class ZombiesController < ApplicationController | |
def show | |
@zombie = Zombie.find(params[:id]) | |
respond_to do |format| | |
format.xml { render xml: @zombie } | |
end | |
end | |
end | |
def create | |
@zombie = Zombie.create(zombie_params) | |
redirect_to zombie_path(@zombie) | |
end | |
class ZombiesController < ApplicationController | |
before_action :find_zombie | |
before_action :check_tweets, only: :show | |
def show | |
render action: :show | |
end | |
def find_zombie | |
@zombie = Zombie.find params[:id] | |
end | |
def check_tweets | |
if @zombie.tweets.size == 0 | |
redirect_to zombies_path | |
end | |
end | |
end | |
TwitterForZombies::Application.routes.draw do | |
resources :zombies | |
end | |
TwitterForZombies::Application.routes.draw do | |
get 'undead' => 'zombies#undead' | |
end | |
TwitterForZombies::Application.routes.draw do | |
get '/undead', to: redirect('/zombies') | |
end | |
TwitterForZombies::Application.routes.draw do | |
root to: 'zombies#index' | |
end | |
TwitterForZombies::Application.routes.draw do | |
get '/zombies/:name', to: 'zombies#index', :as => 'graveyard' | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment