-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding payment and basket into the game
- Loading branch information
1 parent
f29d79d
commit 4333fa9
Showing
40 changed files
with
800 additions
and
33 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
Autotest.add_discovery { "rails" } | ||
Autotest.add_discovery { "rspec2" } | ||
Autotest.add_discovery { "rspec2" } |
23 changes: 23 additions & 0 deletions
23
full-examples/rest_from_scratch/part_2/app/controllers/baskets_controller.rb
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
class BasketsController < ApplicationController | ||
|
||
|
||
include Restfulie::Server::ActionController::Base | ||
|
||
respond_to :xml, :json | ||
|
||
def create | ||
@basket = Basket.new | ||
params[:basket][:items].each do |item| | ||
@basket.items << Item.find(item[:id]) | ||
end | ||
@basket.save | ||
render :text => "", :status => 201, :location => basket_url(@basket) | ||
end | ||
|
||
def show | ||
@basket = Basket.find(params[:id]) | ||
respond_with @basket | ||
end | ||
|
||
|
||
end |
18 changes: 18 additions & 0 deletions
18
full-examples/rest_from_scratch/part_2/app/controllers/payments_controller.rb
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
class PaymentsController < ApplicationController | ||
|
||
include Restfulie::Server::ActionController::Base | ||
|
||
respond_to :xml, :json | ||
|
||
def create | ||
@payment = Basket.find(params[:basket_id]).payments.create(params[:payment]) | ||
render :text => "", :status => 201, :location => basket_payment_url(@payment.basket, @payment) | ||
end | ||
|
||
def show | ||
@payment = Payment.find(params[:id]) | ||
respond_with @payment | ||
end | ||
|
||
|
||
end |
2 changes: 2 additions & 0 deletions
2
full-examples/rest_from_scratch/part_2/app/helpers/baskets_helper.rb
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module BasketsHelper | ||
end |
2 changes: 2 additions & 0 deletions
2
full-examples/rest_from_scratch/part_2/app/helpers/payments_helper.rb
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module PaymentsHelper | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
class Basket < ActiveRecord::Base | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
class Payment < ActiveRecord::Base | ||
end |
17 changes: 17 additions & 0 deletions
17
full-examples/rest_from_scratch/part_2/app/views/baskets/_form.html.erb
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<%= form_for(@basket) do |f| %> | ||
<% if @basket.errors.any? %> | ||
<div id="error_explanation"> | ||
<h2><%= pluralize(@basket.errors.count, "error") %> prohibited this basket from being saved:</h2> | ||
|
||
<ul> | ||
<% @basket.errors.full_messages.each do |msg| %> | ||
<li><%= msg %></li> | ||
<% end %> | ||
</ul> | ||
</div> | ||
<% end %> | ||
|
||
<div class="actions"> | ||
<%= f.submit %> | ||
</div> | ||
<% end %> |
6 changes: 6 additions & 0 deletions
6
full-examples/rest_from_scratch/part_2/app/views/baskets/edit.html.erb
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<h1>Editing basket</h1> | ||
|
||
<%= render 'form' %> | ||
<%= link_to 'Show', @basket %> | | ||
<%= link_to 'Back', baskets_path %> |
21 changes: 21 additions & 0 deletions
21
full-examples/rest_from_scratch/part_2/app/views/baskets/index.html.erb
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<h1>Listing baskets</h1> | ||
|
||
<table> | ||
<tr> | ||
<th></th> | ||
<th></th> | ||
<th></th> | ||
</tr> | ||
|
||
<% @baskets.each do |basket| %> | ||
<tr> | ||
<td><%= link_to 'Show', basket %></td> | ||
<td><%= link_to 'Edit', edit_basket_path(basket) %></td> | ||
<td><%= link_to 'Destroy', basket, :confirm => 'Are you sure?', :method => :delete %></td> | ||
</tr> | ||
<% end %> | ||
</table> | ||
|
||
<br /> | ||
|
||
<%= link_to 'New Basket', new_basket_path %> |
5 changes: 5 additions & 0 deletions
5
full-examples/rest_from_scratch/part_2/app/views/baskets/new.html.erb
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<h1>New basket</h1> | ||
|
||
<%= render 'form' %> | ||
<%= link_to 'Back', baskets_path %> |
5 changes: 5 additions & 0 deletions
5
full-examples/rest_from_scratch/part_2/app/views/baskets/show.html.erb
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<p id="notice"><%= notice %></p> | ||
|
||
|
||
<%= link_to 'Edit', edit_basket_path(@basket) %> | | ||
<%= link_to 'Back', baskets_path %> |
33 changes: 33 additions & 0 deletions
33
full-examples/rest_from_scratch/part_2/app/views/payments/_form.html.erb
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<%= form_for(@payment) do |f| %> | ||
<% if @payment.errors.any? %> | ||
<div id="error_explanation"> | ||
<h2><%= pluralize(@payment.errors.count, "error") %> prohibited this payment from being saved:</h2> | ||
|
||
<ul> | ||
<% @payment.errors.full_messages.each do |msg| %> | ||
<li><%= msg %></li> | ||
<% end %> | ||
</ul> | ||
</div> | ||
<% end %> | ||
|
||
<div class="field"> | ||
<%= f.label :cardnumber %><br /> | ||
<%= f.text_field :cardnumber %> | ||
</div> | ||
<div class="field"> | ||
<%= f.label :cardholder %><br /> | ||
<%= f.text_field :cardholder %> | ||
</div> | ||
<div class="field"> | ||
<%= f.label :amount %><br /> | ||
<%= f.text_field :amount %> | ||
</div> | ||
<div class="field"> | ||
<%= f.label :basket_id %><br /> | ||
<%= f.text_field :basket_id %> | ||
</div> | ||
<div class="actions"> | ||
<%= f.submit %> | ||
</div> | ||
<% end %> |
6 changes: 6 additions & 0 deletions
6
full-examples/rest_from_scratch/part_2/app/views/payments/edit.html.erb
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<h1>Editing payment</h1> | ||
|
||
<%= render 'form' %> | ||
<%= link_to 'Show', @payment %> | | ||
<%= link_to 'Back', payments_path %> |
29 changes: 29 additions & 0 deletions
29
full-examples/rest_from_scratch/part_2/app/views/payments/index.html.erb
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<h1>Listing payments</h1> | ||
|
||
<table> | ||
<tr> | ||
<th>Cardnumber</th> | ||
<th>Cardholder</th> | ||
<th>Amount</th> | ||
<th>Basket</th> | ||
<th></th> | ||
<th></th> | ||
<th></th> | ||
</tr> | ||
|
||
<% @payments.each do |payment| %> | ||
<tr> | ||
<td><%= payment.cardnumber %></td> | ||
<td><%= payment.cardholder %></td> | ||
<td><%= payment.amount %></td> | ||
<td><%= payment.basket_id %></td> | ||
<td><%= link_to 'Show', payment %></td> | ||
<td><%= link_to 'Edit', edit_payment_path(payment) %></td> | ||
<td><%= link_to 'Destroy', payment, :confirm => 'Are you sure?', :method => :delete %></td> | ||
</tr> | ||
<% end %> | ||
</table> | ||
|
||
<br /> | ||
|
||
<%= link_to 'New Payment', new_payment_path %> |
5 changes: 5 additions & 0 deletions
5
full-examples/rest_from_scratch/part_2/app/views/payments/new.html.erb
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<h1>New payment</h1> | ||
|
||
<%= render 'form' %> | ||
<%= link_to 'Back', payments_path %> |
25 changes: 25 additions & 0 deletions
25
full-examples/rest_from_scratch/part_2/app/views/payments/show.html.erb
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<p id="notice"><%= notice %></p> | ||
|
||
<p> | ||
<b>Cardnumber:</b> | ||
<%= @payment.cardnumber %> | ||
</p> | ||
|
||
<p> | ||
<b>Cardholder:</b> | ||
<%= @payment.cardholder %> | ||
</p> | ||
|
||
<p> | ||
<b>Amount:</b> | ||
<%= @payment.amount %> | ||
</p> | ||
|
||
<p> | ||
<b>Basket:</b> | ||
<%= @payment.basket_id %> | ||
</p> | ||
|
||
|
||
<%= link_to 'Edit', edit_payment_path(@payment) %> | | ||
<%= link_to 'Back', payments_path %> |
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
12 changes: 12 additions & 0 deletions
12
full-examples/rest_from_scratch/part_2/db/migrate/20100830180139_create_baskets.rb
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
class CreateBaskets < ActiveRecord::Migration | ||
def self.up | ||
create_table :baskets do |t| | ||
|
||
t.timestamps | ||
end | ||
end | ||
|
||
def self.down | ||
drop_table :baskets | ||
end | ||
end |
16 changes: 16 additions & 0 deletions
16
full-examples/rest_from_scratch/part_2/db/migrate/20100830180203_create_payments.rb
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
class CreatePayments < ActiveRecord::Migration | ||
def self.up | ||
create_table :payments do |t| | ||
t.string :cardnumber | ||
t.string :cardholder | ||
t.decimal :amount | ||
t.integer :basket_id | ||
|
||
t.timestamps | ||
end | ||
end | ||
|
||
def self.down | ||
drop_table :payments | ||
end | ||
end |
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
Oops, something went wrong.