diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index a602a58a..e3b09d95 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1,3 +1,6 @@ +require 'net/http' +require 'date' + class UsersController < ApplicationController include ApplicationHelper @@ -96,6 +99,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 def payment diff --git a/app/views/users/show.html.haml b/app/views/users/show.html.haml index 0b8570e6..1fa0f7ac 100644 --- a/app/views/users/show.html.haml +++ b/app/views/users/show.html.haml @@ -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 diff --git a/config/routes.rb b/config/routes.rb index 11c4fe1b..41bf3a30 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -10,6 +10,7 @@ get 'payment' get 'buy' post 'buy_barcode' + post 'print_label' end collection do get 'stats'