0% found this document useful (0 votes)
46 views6 pages

Class Weapon Activerecord::Base Belongs - To:Zombie End: Has - Many

The document defines models and relationships between Zombies, Weapons, and Tweets. It also defines controllers to handle CRUD operations for Tweets and Zombies. Views are defined to display lists and details of Tweets and Zombies, and routes are set up to handle zombie and tweet URLs.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views6 pages

Class Weapon Activerecord::Base Belongs - To:Zombie End: Has - Many

The document defines models and relationships between Zombies, Weapons, and Tweets. It also defines controllers to handle CRUD operations for Tweets and Zombies. Views are defined to display lists and details of Tweets and Zombies, and routes are set up to handle zombie and tweet URLs.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
You are on page 1/ 6

T= Tweet.find(3) puts t[:id] puts t.id t= Tweet.new t.status = 'jjj' t.zombie = jimmm t.save Tweet.

create(:status => fff, :zombie=> ddd) Tweet.count t= Tweet.find(3) t.zombie = sss t.save t= Tweet.find(2) t.destroy class Zombie < ActiveRecord::Base validates :name, :presence => true, :uniqueness => true end class Weapon < ActiveRecord::Base belongs_to :zombie end
class Zombie < ActiveRecord::Base

has_many :weapons
end class Weapon < ActiveRecord::Base belongs_to :zombie end

z = Zombie.find(1) z.weapons

z= Zombie.find(2) t=Tweet.create(:status=>aaa, :zombie=>z) t.zombie t.zombie.name ash=Zombie.find(1) ash.tweets.count ash.tweets

<head> <%= stylesheet_link_tag :all%> <%= javascript_include_tag :defaults%> <%= csrf_meta_tag %> </head> <body> <%= yield %> </body> <% tweet = Tweet.find(1) %> <h1><%= tweet.status %></h1> <img src=/https/www.scribd.com/images/twitter.png /> <p>Posted by <%= tweet.zombie.name %></p> <%= link_to tweet.zombie.name, zombie_path(tweet.zombie) %> <%= link_to tweet.zombie.name, tweet.zombie %> <a href=/https/www.scribd.com/zombie/1>Ash</a> <h1>Listing tweets</h1> <table> <tr> <th>Status</th> <th>Zombie</th> </tr> <% Tweet.all.each do | tweet | %> <tr> <td><%= tweet.status %></td> <td><%= tweet.zombie.name %></td> </tr> <% end %> </table> <% Tweet.all.each do | tweet | %> <tr> <td><%= link_to tweet.status, tweet %></td> <td><%= link_to tweet.zombie.name, tweet.zombie %></td> </tr> <% end %> <% tweets = Tweet.all %> <% Tweet.each do | tweet | %> <% end %> <% if tweets.size == 0 %><% if tweets.empty? %> <em>No tweets found</em>

<% end %>

<% tweets.each do | tweet | %> <tr> <td><%= link_to tweet.status, tweet %></td> <td><%= link_to tweet.zombie.name, tweet.zombie %></td> <td><%= link_to Edit, edit_tweet_path(tweet) %></td> <td><%= link_to Delete, tweet, :method => :delete %></td> </tr> <% end %> <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>

class TweetsController < ApplicationController def show @tweet = Tweet.find(params[:id]) render :action => 'status' end end <h1><%= @tweet.status %></h1> <p>Posted by <%= @tweet.zombie.name %></p> @tweet = Tweet.create(:status => params[:status]) params = {:tweet => { :status => aaaa}} @tweet = Tweet.create(:status => params[:tweet][:status]) @tweet = Tweet.create(params[:tweet]) class TweetsController < ApplicationController def index # list all tweets def new # new tweet form def edit # edit tweet form def create # create new tweet def update #update a tweet def destroy # delete def show # show a single tweet @tweet = Tweet.find(params[:id]) respond_to do |format| format.html # show.html.erb format.xml { render :xml => @tweet} format.json{render :json => @tweet} end end class TweetsController < ApplicationController def edit # edit tweet form @tweet = Tweet.find(params[:id]) if session[:zombie_id] != @tweet.zombie_id flash [:notice] = sorrys redirect_to(tweet_path) end end end

class TweetsController < ApplicationController def edit # edit tweet form @tweet = Tweet.find(params[:id]) if session[:zombie_id] != @tweet.zombie_id redirect_to(tweet_path) :notice => sorrys end end end <head> <%= stylesheet_link_tag :all%> <%= javascript_include_tag :defaults%> <%= csrf_meta_tag %> </head> <body> <img src=/https/www.scribd.com/image/twitter.png /> <% if flash[:notice] %> <div id=notice><%= flash[:notice] %></div> <% end %> <%= yield %> </body> class TweetsController < ApplicationController before_filter :get_tweet, :only =>[:edit, :update, :destroy] before_filter :check_auth, :only =>[:edit, :update, :destroy] def get_tweet @tweet = Tweet.find(params[:id]) end def check_auth if session[:zombie_id] != @tweet.zombie_id flash[:notice] = sorrys redirect_to tweet_path end end end end class ZombiesController < ApplicationController def create @zombie = Zombie.create(params[:zombie]) redirect_to zombie_path(@zombie) end end

TwitterForZombies::Application.routes.draw do resources :zombies end TwitterForZombies::Application.routes.draw do match '/undead' => redirect('/zombies') end

TwitterForZombies::Application.routes.draw do
root :to => 'zombies#index' end

TwitterForZombies::Application.routes.draw do
match '/zombies/:name' => 'zombies#index', :as => 'graveyard' end

You might also like