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,5 +1,8 @@
/* User profile */ /* User profile */
.user_info {
text-align: center;
}
.user_info h2 { .user_info h2 {
line-height: 45px; line-height: 45px;
@ -11,6 +14,29 @@
text-align: right; 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 { .balance {
padding: 12px 0; padding: 12px 0;
text-align: center; text-align: center;
@ -18,6 +44,7 @@
font-size: 16px; font-size: 16px;
width: 60%; width: 60%;
margin: auto; margin: auto;
margin-top: 10px;
background-color: #FF7F00; background-color: #FF7F00;
color: white; color: white;
} }

View file

@ -6,6 +6,7 @@ class OrdersController < ApplicationController
def new def new
@user = User.find(params[:user_id]) @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: "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 = @user.orders.build
# products = @user.products.select("products.*", "sum(order_items.count) as count").group(:product_id).order("count desc") # 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 def create
@user = User.find(params[:user_id]) @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: "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) @order = @user.orders.build(order_params)

View file

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

View file

@ -3,6 +3,7 @@
<div class="user_info"> <div class="user_info">
<h5><%= link_to "[Edit profile]" , edit_user_registration_path if current_user == @user%></h5> <h5><%= link_to "[Edit profile]" , edit_user_registration_path if current_user == @user%></h5>
<h2><%= @user.nickname %> (<%= @user.full_name %>)</h2> <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 class="balance">BALANCE: <%= euro(@user.balance) %></div>
</div> </div>
@ -19,6 +20,4 @@
<%= will_paginate @orders %> <%= will_paginate @orders %>
</div> </div>
<% end %> <% end %>
</div> </div>