Skip to content

Instantly share code, notes, and snippets.

View enricostano's full-sized avatar

Enrico Stano enricostano

View GitHub Profile
@enricostano
enricostano / gist:3160160
Created July 22, 2012 16:10
find /lib/* -type f -exec yaourt -Qo -- {} + 1>/dev/null
[enrico@archlap lib]$ find /lib/* -type f -exec yaourt -Qo -- {} + 1>/dev/null
error: No package owns /lib/modules/3.1.9-2-ARCH/modules.usbmap
error: No package owns /lib/modules/3.1.9-2-ARCH/modules.pcimap
error: No package owns /lib/modules/3.1.9-2-ARCH/modules.inputmap
error: No package owns /lib/modules/3.1.9-2-ARCH/modules.isapnpmap
error: No package owns /lib/modules/3.1.9-2-ARCH/modules.ieee1394map
error: No package owns /lib/modules/3.1.9-2-ARCH/modules.ccwmap
error: No package owns /lib/modules/3.1.9-2-ARCH/modules.seriomap
error: No package owns /lib/modules/3.1.9-2-ARCH/modules.ofmap
error: No package owns /lib/modules/3.2.6-2-ARCH/modules.alias
class Project < ActiveRecord::Base
attr_accessible :name, :start, :stop
belongs_to :institution
validates :name, :start, :stop, :presence => true
end
class Institution < ActiveRecord::Base
attr_accessible :email, :name, :phone
has_many :projects, :dependent => :destroy
validates :email, :name, :phone, :presence => true
@enricostano
enricostano / gist:3257741
Created August 4, 2012 13:25
Project class
class Project < ActiveRecord::Base
attr_accessible :name, :start, :stop, :institution_id
belongs_to :institution
validates :name, :start, :stop, :institution, :presence => true
validate :start_before_stop_date
def start_before_stop_date
if self.start && self.stop && self.start >= self.stop
self.errors.add :start, ' deve essere prima di stop'
end
@enricostano
enricostano / gist:3257763
Created August 4, 2012 13:27
Project test
require 'test_helper'
class ProjectTest < ActiveSupport::TestCase
test "should not save empty project" do
project = Project.new
assert !project.save, "Saved empty project"
end
end
@enricostano
enricostano / gist:3257767
Created August 4, 2012 13:28
Project fixtures
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
one:
name: MyString
institution_id: 1
start: 2012-08-03
stop: 2012-08-03
two:
name: MyString
@enricostano
enricostano / gist:3258302
Created August 4, 2012 15:16
Project test 2
test "stop is greater than start date" do
project = Project.new(:name => "Puppa",
:institution_id => 1)
project.start = "2012-08-03"
project.stop = "2012-08-10"
assert project.valid?
end
@enricostano
enricostano / user.rb
Created August 21, 2012 17:51
user model
class User < ActiveRecord::Base
has_and_belongs_to_many :roles
accepts_nested_attributes_for :roles
has_many :carts
# Include default devise modules. Others available are:
# :token_authenticatable, :confirmable,
# :lockable, :timeoutable and :omniauthable
@enricostano
enricostano / role.rb
Created August 21, 2012 17:51
role model
class Role < ActiveRecord::Base
has_and_belongs_to_many :users
end
@enricostano
enricostano / index.html.erb
Created August 21, 2012 17:53
dashboard view
<div id="left_dashboard_column">
<div class="div_interno" id="projects_by_institution">
<h2>Progetti attivi</h2>
<%= render 'projects/nextbyinstitution' %>
<% if current_user.role? :super_admin %>
<%= link_to 'Elenco progetti', projects_path %> |
<%= link_to 'Nuovo progetto', new_project_path %>
<% end %>
</div>
</div>
@enricostano
enricostano / orders_controller.rb
Created August 27, 2012 18:04
create order CTRL
# POST /orders
# POST /orders.json
def create
@order = Order.new(params[:order])
cart = session[:cart]
cart.each do | id, quantity |
item = Project.find_by_id(id)
@line_item = LineItem.new