Scaffolding in some mashy stuff

This commit is contained in:
Dan Buch
2012-03-04 11:51:35 -05:00
parent fedeefef98
commit 57f63fd62f
29 changed files with 626 additions and 322 deletions

View File

@@ -0,0 +1,85 @@
class MashesController < ApplicationController
# GET /mashes
# GET /mashes.xml
def index
@mashes = Mash.all
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @mashes }
end
end
# GET /mashes/1
# GET /mashes/1.xml
def show
@mash = Mash.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @mash }
end
end
# GET /mashes/new
# GET /mashes/new.xml
def new
@mash = Mash.new
respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @mash }
end
end
# GET /mashes/1/edit
def edit
@mash = Mash.find(params[:id])
end
# POST /mashes
# POST /mashes.xml
def create
@mash = Mash.new(params[:mash])
respond_to do |format|
if @mash.save
flash[:notice] = 'Mash was successfully created.'
format.html { redirect_to(@mash) }
format.xml { render :xml => @mash, :status => :created, :location => @mash }
else
format.html { render :action => "new" }
format.xml { render :xml => @mash.errors, :status => :unprocessable_entity }
end
end
end
# PUT /mashes/1
# PUT /mashes/1.xml
def update
@mash = Mash.find(params[:id])
respond_to do |format|
if @mash.update_attributes(params[:mash])
flash[:notice] = 'Mash was successfully updated.'
format.html { redirect_to(@mash) }
format.xml { head :ok }
else
format.html { render :action => "edit" }
format.xml { render :xml => @mash.errors, :status => :unprocessable_entity }
end
end
end
# DELETE /mashes/1
# DELETE /mashes/1.xml
def destroy
@mash = Mash.find(params[:id])
@mash.destroy
respond_to do |format|
format.html { redirect_to(mashes_url) }
format.xml { head :ok }
end
end
end

View File

@@ -0,0 +1,2 @@
module MashesHelper
end

View File

@@ -0,0 +1,2 @@
class Map < ActiveRecord::Base
end

View File

@@ -0,0 +1,2 @@
class Mash < ActiveRecord::Base
end

View File

@@ -0,0 +1,17 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
<title>Mashes: <%= controller.action_name %></title>
<%= stylesheet_link_tag 'scaffold' %>
</head>
<body>
<p style="color: green"><%= flash[:notice] %></p>
<%= yield %>
</body>
</html>

View File

@@ -0,0 +1,28 @@
<h1>Editing mash</h1>
<% form_for(@mash) do |f| %>
<%= f.error_messages %>
<p>
<%= f.label :requester %><br />
<%= f.text_field :requester %>
</p>
<p>
<%= f.label :map_a %><br />
<%= f.text_field :map_a %>
</p>
<p>
<%= f.label :map_b %><br />
<%= f.text_field :map_b %>
</p>
<p>
<%= f.label :winner %><br />
<%= f.text_field :winner %>
</p>
<p>
<%= f.submit 'Update' %>
</p>
<% end %>
<%= link_to 'Show', @mash %> |
<%= link_to 'Back', mashes_path %>

View File

@@ -0,0 +1,26 @@
<h1>Listing mashes</h1>
<table>
<tr>
<th>Requester</th>
<th>Map a</th>
<th>Map b</th>
<th>Winner</th>
</tr>
<% @mashes.each do |mash| %>
<tr>
<td><%=h mash.requester %></td>
<td><%=h mash.map_a %></td>
<td><%=h mash.map_b %></td>
<td><%=h mash.winner %></td>
<td><%= link_to 'Show', mash %></td>
<td><%= link_to 'Edit', edit_mash_path(mash) %></td>
<td><%= link_to 'Destroy', mash, :confirm => 'Are you sure?', :method => :delete %></td>
</tr>
<% end %>
</table>
<br />
<%= link_to 'New mash', new_mash_path %>

View File

@@ -0,0 +1,27 @@
<h1>New mash</h1>
<% form_for(@mash) do |f| %>
<%= f.error_messages %>
<p>
<%= f.label :requester %><br />
<%= f.text_field :requester %>
</p>
<p>
<%= f.label :map_a %><br />
<%= f.text_field :map_a %>
</p>
<p>
<%= f.label :map_b %><br />
<%= f.text_field :map_b %>
</p>
<p>
<%= f.label :winner %><br />
<%= f.text_field :winner %>
</p>
<p>
<%= f.submit 'Create' %>
</p>
<% end %>
<%= link_to 'Back', mashes_path %>

View File

@@ -0,0 +1,23 @@
<p>
<b>Requester:</b>
<%=h @mash.requester %>
</p>
<p>
<b>Map a:</b>
<%=h @mash.map_a %>
</p>
<p>
<b>Map b:</b>
<%=h @mash.map_b %>
</p>
<p>
<b>Winner:</b>
<%=h @mash.winner %>
</p>
<%= link_to 'Edit', edit_mash_path(@mash) %> |
<%= link_to 'Back', mashes_path %>