--- /dev/null
+class GameplatformController < ApplicationController
+ def index
+ list
+ render :action => 'list'
+ end
+
+ # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
+ verify :method => :post, :only => [ :destroy, :create, :update ],
+ :redirect_to => { :action => :list }
+
+ def list
+ @gameplatform_pages, @gameplatforms = paginate :gameplatforms, :per_page => 10
+ end
+
+ def show
+ @gameplatform = Gameplatform.find(params[:id])
+ end
+
+ def new
+ @gameplatform = Gameplatform.new
+ end
+
+ def create
+ @gameplatform = Gameplatform.new(params[:gameplatform])
+ if @gameplatform.save
+ flash[:notice] = 'Gameplatform was successfully created.'
+ redirect_to :action => 'list'
+ else
+ render :action => 'new'
+ end
+ end
+
+ def edit
+ @gameplatform = Gameplatform.find(params[:id])
+ end
+
+ def update
+ @gameplatform = Gameplatform.find(params[:id])
+ if @gameplatform.update_attributes(params[:gameplatform])
+ flash[:notice] = 'Gameplatform was successfully updated.'
+ redirect_to :action => 'show', :id => @gameplatform
+ else
+ render :action => 'edit'
+ end
+ end
+
+ def destroy
+ Gameplatform.find(params[:id]).destroy
+ redirect_to :action => 'list'
+ end
+end
--- /dev/null
+module GameplatformHelper
+end
return Gamegenre.find(game_genre).name
end
+ def game_platform
+ return Gameplatform.find(platform).name
+ end
+
def calculated_price
# FIXME: generate this based on day of week, newrelease
day_of_week = Time.now.to_date.wday
--- /dev/null
+class Gameplatform < ActiveRecord::Base
+end
<%= check_box 'game', 'newrelease' %></p>
<p><label for="game_platform">Platform</label><br/>
-<%= text_field 'game', 'platform' %></p>
+<%= select 'game', 'platform', Gameplatform.find(:all).collect {|c| [c.name.to_s, c.id] } %></p>
<p><label for="game_genre">Genre</label><br/>
<%= select 'game', 'game_genre', Gamegenre.find(:all).collect {|c| [c.name.to_s, c.id] } %></p>
<td><%=h game.title %></td>
<td><%=h game.newrelease %></td>
<td><%=h game.genre %></td>
- <td>FIXME</td>
+ <td><%=h game.game_platform %></td>
<td><%= link_to 'Show', :action => 'show', :id => game %></td>
<td><%= link_to 'Edit', :action => 'edit', :id => game %></td>
<td><%= link_to 'Destroy', { :action => 'destroy', :id => game }, :confirm => 'Are you sure?', :method => :post %></td>
--- /dev/null
+<%= error_messages_for 'gameplatform' %>
+
+<!--[form:gameplatform]-->
+<p><label for="gameplatform_name">Name</label><br/>
+<%= text_field 'gameplatform', 'name' %></p>
+<!--[eoform:gameplatform]-->
+
--- /dev/null
+<h1>Editing gameplatform</h1>
+
+<% form_tag :action => 'update', :id => @gameplatform do %>
+ <%= render :partial => 'form' %>
+ <%= submit_tag 'Edit' %>
+<% end %>
+
+<%= link_to 'Show', :action => 'show', :id => @gameplatform %> |
+<%= link_to 'Back', :action => 'list' %>
--- /dev/null
+<h1>Listing gameplatforms</h1>
+
+<table>
+ <tr>
+ <% for column in Gameplatform.content_columns %>
+ <th><%= column.human_name %></th>
+ <% end %>
+ </tr>
+
+<% for gameplatform in @gameplatforms %>
+ <tr>
+ <% for column in Gameplatform.content_columns %>
+ <td><%=h gameplatform.send(column.name) %></td>
+ <% end %>
+ <td><%= link_to 'Show', :action => 'show', :id => gameplatform %></td>
+ <td><%= link_to 'Edit', :action => 'edit', :id => gameplatform %></td>
+ <td><%= link_to 'Destroy', { :action => 'destroy', :id => gameplatform }, :confirm => 'Are you sure?', :method => :post %></td>
+ </tr>
+<% end %>
+</table>
+
+<%= link_to 'Previous page', { :page => @gameplatform_pages.current.previous } if @gameplatform_pages.current.previous %>
+<%= link_to 'Next page', { :page => @gameplatform_pages.current.next } if @gameplatform_pages.current.next %>
+
+<br />
+
+<%= link_to 'New gameplatform', :action => 'new' %>
--- /dev/null
+<h1>New gameplatform</h1>
+
+<% form_tag :action => 'create' do %>
+ <%= render :partial => 'form' %>
+ <%= submit_tag "Create" %>
+<% end %>
+
+<%= link_to 'Back', :action => 'list' %>
--- /dev/null
+<% for column in Gameplatform.content_columns %>
+<p>
+ <b><%= column.human_name %>:</b> <%=h @gameplatform.send(column.name) %>
+</p>
+<% end %>
+
+<%= link_to 'Edit', :action => 'edit', :id => @gameplatform %> |
+<%= link_to 'Back', :action => 'list' %>
--- /dev/null
+<!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>Gameplatform: <%= controller.action_name %></title>
+ <%= stylesheet_link_tag 'scaffold' %>
+</head>
+<body>
+
+<p style="color: green"><%= flash[:notice] %></p>
+
+<%= yield %>
+
+</body>
+</html>
--- /dev/null
+class CreateGameplatforms < ActiveRecord::Migration
+ def self.up
+ create_table :gameplatforms do |t|
+ t.column :name, :string, :null => false
+ end
+ end
+
+ def self.down
+ drop_table :gameplatforms
+ end
+end
# migrations feature of ActiveRecord to incrementally modify your database, and
# then regenerate this schema definition.
-ActiveRecord::Schema.define(:version => 24) do
+ActiveRecord::Schema.define(:version => 25) do
create_table "bitems", :force => true do |t|
t.column "customer_id", :integer, :null => false
t.column "name", :string, :null => false
end
+ create_table "gameplatforms", :force => true do |t|
+ t.column "name", :string, :null => false
+ end
+
create_table "medias", :force => true do |t|
t.column "name", :string, :null => false
end
--- /dev/null
+# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
+one:
+ id: 1
+two:
+ id: 2
--- /dev/null
+require File.dirname(__FILE__) + '/../test_helper'
+require 'gameplatform_controller'
+
+# Re-raise errors caught by the controller.
+class GameplatformController; def rescue_action(e) raise e end; end
+
+class GameplatformControllerTest < Test::Unit::TestCase
+ fixtures :gameplatforms
+
+ def setup
+ @controller = GameplatformController.new
+ @request = ActionController::TestRequest.new
+ @response = ActionController::TestResponse.new
+
+ @first_id = gameplatforms(:first).id
+ end
+
+ def test_index
+ get :index
+ assert_response :success
+ assert_template 'list'
+ end
+
+ def test_list
+ get :list
+
+ assert_response :success
+ assert_template 'list'
+
+ assert_not_nil assigns(:gameplatforms)
+ end
+
+ def test_show
+ get :show, :id => @first_id
+
+ assert_response :success
+ assert_template 'show'
+
+ assert_not_nil assigns(:gameplatform)
+ assert assigns(:gameplatform).valid?
+ end
+
+ def test_new
+ get :new
+
+ assert_response :success
+ assert_template 'new'
+
+ assert_not_nil assigns(:gameplatform)
+ end
+
+ def test_create
+ num_gameplatforms = Gameplatform.count
+
+ post :create, :gameplatform => {}
+
+ assert_response :redirect
+ assert_redirected_to :action => 'list'
+
+ assert_equal num_gameplatforms + 1, Gameplatform.count
+ end
+
+ def test_edit
+ get :edit, :id => @first_id
+
+ assert_response :success
+ assert_template 'edit'
+
+ assert_not_nil assigns(:gameplatform)
+ assert assigns(:gameplatform).valid?
+ end
+
+ def test_update
+ post :update, :id => @first_id
+ assert_response :redirect
+ assert_redirected_to :action => 'show', :id => @first_id
+ end
+
+ def test_destroy
+ assert_nothing_raised {
+ Gameplatform.find(@first_id)
+ }
+
+ post :destroy, :id => @first_id
+ assert_response :redirect
+ assert_redirected_to :action => 'list'
+
+ assert_raise(ActiveRecord::RecordNotFound) {
+ Gameplatform.find(@first_id)
+ }
+ end
+end
--- /dev/null
+require File.dirname(__FILE__) + '/../test_helper'
+
+class GameplatformTest < Test::Unit::TestCase
+ fixtures :gameplatforms
+
+ # Replace this with your real tests.
+ def test_truth
+ assert true
+ end
+end