Skip to content

Commit

Permalink
Print labels with username and current date.
Browse files Browse the repository at this point in the history
  • Loading branch information
YtvwlD committed Sep 27, 2017
1 parent ddc4df5 commit f439dde
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
26 changes: 26 additions & 0 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
require 'net/http'
require 'date'

class UsersController < ApplicationController
# GET /users
# GET /users.json
Expand Down Expand Up @@ -126,6 +129,29 @@ def buy_barcode
buy_drink
end
end

# POST /users/1/print_label
# POST /users/1/print_label.json
def print_label
@user = User.find(params[:id])
text = "#{@user.name} #{Date.today.iso8601}"
uri = URI('http://labello/print')
res = Net::HTTP.post_form(
uri,
'text' => text,
'font' => 'lettergothic',
'align' => 'left',
'fontSize' => '42'
)
result = res.body
respond_to do |format|
format.html do
flash[:info] = "Labello responded with '#{result}'."
redirect_to @user
end
format.json { render json: {"result" => result } }
end
end

# GET /users/1/pay?amount=1.5
# GET /users/1/pay.json?amount=1.5
Expand Down
2 changes: 2 additions & 0 deletions app/views/users/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
- if @user.audit?
%li
= link_to 'show logs', audits_path(:user => @user)
%li
= link_to 'print label', print_label_user_path(@user), :method => :post
%li
= link_to 'delete user', @user, :method => :delete, :data => {:confirm => "Really delete #{@user.name}’s account?"}
.page-header
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
get 'payment'
get 'buy'
post 'buy_barcode'
post 'print_label'
end
collection do
get 'stats'
Expand Down

0 comments on commit f439dde

Please sign in to comment.