Skip to content

Instantly share code, notes, and snippets.

# Stock allocator
This article explains the concept of a stock allocator and its usage.
During the checkout process, after the delivery step, the order stocks the ordered stock items
to ship them.
The stock allocator defines the logic with which these packages are created.
The allocator is called by `Spree::Stock::SimpleCoordinator` when allocating inventory for an order.
class AddTagsToPosts < ActiveRecord::Migration
def migrate
add_column :posts, :tags, :text
end
end
#include<stdio.h>
int main() {
int numbers[2];
printf("Inserisci il primo numero: ");
scanf("%d", &numbers[0]);
printf("Inserisci il secondo numero: ");
scanf("%d", &numbers[1]);
class House
has_many :photos
end
RSpec.describe Photo
let(:house) { House.create! }
subject { described_class.new(house: house) }
it 'is marked as cover when saved' do
expect {
subject.save!
subject.reload
}.to change(subject, :cover).to(true)
end
class Review < ActiveRecord::Base
belongs_to :book
trigger.after(:insert) do
<<-SQL
UPDATE books SET reviews_count = reviews_count + 1 WHERE id = NEW.book_id;
SQL
end
trigger.after(:update).of(:book_id) do
RSpec.describe Review do
let(:book) { Book.create! }
subject { Review.new(book: book) }
it "increments the book's reviews_count when saving" do
expect {
subject.save!
}.to change(book, :reviews_count).by(1)
end
class BooksController < ApplicationController
def top_ten
@books = Book.order('reviews_count DESC').limit(10)
end
end
class Book < ActiveRecord::Base
has_many :reviews
end
<?php
$period = isset($_POST['period']) ? trim($_POST['period']) : '';
echo <<<EOF
<form method="post" action="{$_SERVER['REQUEST_URI']}">
<div>
<label for="period">Periodo:</label>
<input type="text" name="period" id="period" value="{$period}">
</div>