Skip to content

Instantly share code, notes, and snippets.

<script type="text/javascript" >
jQuery.ajaxSetup({
'beforeSend': function(xhr) {xhr.setRequestHeader("Accept", "text/javascript")}
});
jQuery.fn.submitWithAjax = function() {
this.submit(function() {
$.post(this.action + '.js', $(this).serialize(), null, "script");
return false;
})
def create_po
provides :js
po = params[:purchase_order]
# do the creating job for the po
render
end
<% if @purchase_order %>
$("div.remote_<%= @counter %>").text("done");
<% else %>
<% if @params['vendor_name'] == "Enter the vendor's name" || @params['purchase_order'].nil? %>
$("#vendor_name").focus();
$("#error_<%=@counter%>").after('<span class="error">Vendor is required.</span>');
<% end %>
<% @params['cb3_ids'].each do |cb3_id| %>
<% %w{quantity unitsize price bt tcost}.each do |word| %>
Merb::BootLoader.after_app_loads do
Merb.add_mime_type(:pdf, :to_pdf, %w[application/pdf], "Content-Encoding" => "gzip")
end
<%= form_for(@price_letter, :action => resource(:ordering, @price_letter, :priceletter, :format => "pdf"), :class => "form") do %>
# fields for ....
<% end =%>
def priceletter
provides :pdf
...
end
pdf = Prawn::Document.new(
:page_size => "A4",
:left_margin => 2.cm,
:right_margin => 2.cm,
:top_margin => 2.cm,
:bottom_margin => 1.5.cm
)
# logo
logo = image_dir + 'logo.jpg'
pdf.image logo, :position => :center
# price_letter.pdf.erb
<%=
require "prawn/measurement_extensions"
require "prawn/table"
pdf = Prawn::Document.new(
:page_size => "A4",
:left_margin => 2.cm,
:right_margin => 2.cm,
:top_margin => 2.cm,
#I am not sure if this is the feature(it is designed to do so),
# or I'm doing it wrong. Here is the situation I have:
# as of DM version: 0.9.9
class Order
before :destroy, :destroy_items
....
has n, items ...
def destroy_items
# from dm-constraints/lib/dm-constraints/delete_constraint.rb
when :destroy!
if children
# not sure why but this lazy_load is necessary
# otherwise children will not be deleted with destroy!
children.lazy_load
children.destroy!
end
....