Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save matheusvetor/9891957 to your computer and use it in GitHub Desktop.
Save matheusvetor/9891957 to your computer and use it in GitHub Desktop.
class CreateCashes < ActiveRecord::Migration
def change
create_table :cashes do |t|
t.datetime :start_at
t.datetime :end_at
t.decimal :value_open
t.decimal :value_phisic_closed
t.decimal :value_system_closed
t.timestamps
end
end
end
<%= simple_form_for @cash do |f| %>
<div class="form-group">
<%= f.input :value_open, :input_html =>{:class=>"form-control"} %>
</div>
<%= button_tag(type: :submit, :class=>"btn btn-success") do %>
<i class="icon-save"></i> Registar abertura de caixa
<% end %>
<% end %>
class ApplicationController < ActionController::Base
before_filter :authenticate_user!
before_filter :authenticate_cash
def after_sign_in_path_for(resource)
new_cash_path
end
def authenticate_cash
redirect_to new_cah_path if session[:cash_id].nil?
end
end
class CashesController < ApplicationController
def index
start_at = current_user.current_sign_in_at
@billings = Billing.where("created_at>?",start_at)
end
def new
@cash = Cash.new
end
def create
@cash = Cash.new(cash_params)
@cash.start_at = current_user.current_sign_in_at
if @cash.save
session[:cash_id] = @cash.id
redirect_to root_url
end
end
def cash_params
params.require(:cash).permit(:value_open, :value_phisic_closed, :value_system_closed)
end
end
class Cashing < ActiveRecord::Base
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment