Add order button on user profile page

This commit is contained in:
benji 2015-03-02 16:10:54 +01:00
parent 35876715f6
commit b8b89aa779
4 changed files with 42 additions and 13 deletions

View file

@ -1,14 +1,40 @@
/* User profile */
.user_info {
text-align: center;
}
.user_info h2 {
line-height: 45px;
text-align: center;
}
.user_info h5 {
margin-right: 10px;
text-align: right;
margin-right: 10px;
text-align: right;
}
.user_info .button_to input[type="submit"] {
font-size: 16px;
color: #FFF;
padding: 12px 50px 12px 50px;
border: 1px solid #999;
width: 60%;
font-family: monospace;
text-shadow: 0px 1px 1px #666;
text-decoration: none;
border-radius: 4px;
-moz-border-radius: 4px;
-webkit-border-radius: 4px;
background: #64a724;
background: -moz-linear-gradient(top, #64a724 0%, #579727 50%, #58982a 51%, #498c25 100%);
background: -webkit-gradient(linear, left top, left bottom, from(#64a724), to(#498c25), color-stop(0.4, #579727), color-stop(0.5, #58982a), color-stop(.9, #498c25), color-stop(0.9, #498c25));
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#64a724', endColorstr='#498c25', GradientType=0 );
cursor: pointer;
}
.balance {
@ -18,6 +44,7 @@
font-size: 16px;
width: 60%;
margin: auto;
margin-top: 10px;
background-color: #FF7F00;
color: white;
}

View file

@ -6,6 +6,7 @@ class OrdersController < ApplicationController
def new
@user = User.find(params[:user_id])
redirect_to root_path, flash: { error: "Koelkast can't order things." } if @user.koelkast?
redirect_to root_path, flash: { error: "Please don't order stuff for other people" } unless current_user.koelkast? || current_user == @user
@order = @user.orders.build
# products = @user.products.select("products.*", "sum(order_items.count) as count").group(:product_id).order("count desc")
@ -16,6 +17,7 @@ class OrdersController < ApplicationController
def create
@user = User.find(params[:user_id])
redirect_to root_path, flash: { error: "Koelkast can't order things." } if @user.koelkast?
redirect_to root_path, flash: { error: "Please don't order stuff for other people" } unless current_user.koelkast? || current_user == @user
@order = @user.orders.build(order_params)

View file

@ -11,6 +11,7 @@ class Ability
elsif user[:id]
can :read, :all
can :update, User
can :create, Order
end
end
end

View file

@ -3,22 +3,21 @@
<div class="user_info">
<h5><%= link_to "[Edit profile]" , edit_user_registration_path if current_user == @user%></h5>
<h2><%= @user.nickname %> (<%= @user.full_name %>)</h2>
<%= button_to "PLACE ORDER!", new_user_order_path(@user), method: :get %>
<div class="balance">BALANCE: <%= euro(@user.balance) %></div>
</div>
<% if @user.orders.any? %>
<div class="stats">
<h4>Total products</h4>
Total: <br/><ul><li><%=@categories.map{|c| pluralize(c.count, c.category)}.join(", ")%></li></ul>
<br/>
Specifics:<br/>
<%= render partial: "products/product_row", collection: @products, as: :product %>
<div class="stats">
<h4>Total products</h4>
Total: <br/><ul><li><%=@categories.map{|c| pluralize(c.count, c.category)}.join(", ")%></li></ul>
<br/>
Specifics:<br/>
<%= render partial: "products/product_row", collection: @products, as: :product %>
<h4>All orders (<%= @user.orders_count %>)</h4>
<%= render @orders %>
<%= will_paginate @orders %>
</div>
<% end %>
</div>