浏览代码

Iteration D3.

master
父节点
当前提交
e2a4ad7e16
共有 5 个文件被更改,包括 24 次插入6 次删除
  1. +4
    -0
      app/assets/stylesheets/store.scss
  2. +7
    -2
      app/controllers/line_items_controller.rb
  3. +7
    -2
      app/views/carts/show.html.erb
  4. +1
    -0
      app/views/store/index.html.erb
  5. +5
    -2
      test/controllers/line_items_controller_test.rb

+ 4
- 0
app/assets/stylesheets/store.scss 查看文件

@@ -37,6 +37,10 @@
margin-left: 100px;
margin-top: 0.5em;
margin-bottom: 0.8em;

form, div {
display: inline;
}
}

.price {


+ 7
- 2
app/controllers/line_items_controller.rb 查看文件

@@ -1,6 +1,10 @@
class LineItemsController < ApplicationController
include CurrentCart
before_action :set_cart, only: [:create]
before_action :set_line_item, only: [:show, :edit, :update, :destroy]

# TODO: Create counter from play time.

# GET /line_items
# GET /line_items.json
def index
@@ -24,11 +28,12 @@ class LineItemsController < ApplicationController
# POST /line_items
# POST /line_items.json
def create
@line_item = LineItem.new(line_item_params)
product = Product.find(params[:product_id])
@line_item = @cart.line_items.build(product: product)

respond_to do |format|
if @line_item.save
format.html { redirect_to @line_item, notice: 'Line item was successfully created.' }
format.html { redirect_to @line_item.cart, notice: 'Line item was successfully created.' }
format.json { render :show, status: :created, location: @line_item }
else
format.html { render :new }


+ 7
- 2
app/views/carts/show.html.erb 查看文件

@@ -1,4 +1,9 @@
<p id="notice"><%= notice %></p>

<%= link_to 'Edit', edit_cart_path(@cart) %> |
<%= link_to 'Back', carts_path %>
<h2>Your Pragmatic Cart</h2>

<ul>
<% @cart.line_items.each do |item| %>
<li><%= item.product.title %></li>
<% end %>
</ul>

+ 1
- 0
app/views/store/index.html.erb 查看文件

@@ -11,6 +11,7 @@
<%= sanitize(product.description) %>
<div class="price_line">
<span class="price"><%= number_to_currency(product.price) %></span>
<%= button_to 'Add To Cart', line_items_path(product_id: product) %>
</div>
</div>
<% end %>


+ 5
- 2
test/controllers/line_items_controller_test.rb 查看文件

@@ -17,10 +17,13 @@ class LineItemsControllerTest < ActionDispatch::IntegrationTest

test "should create line_item" do
assert_difference('LineItem.count') do
post line_items_url, params: { line_item: { cart_id: @line_item.cart_id, product_id: @line_item.product_id } }
post line_items_url, params: { product_id: products(:ruby).id }
end

assert_redirected_to line_item_url(LineItem.last)
follow_redirect!

assert_select 'h2', 'Your Pragmatic Cart'
assert_select 'li', 'Programming Ruby 1.9'
end

test "should show line_item" do


正在加载...
取消
保存