<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>redirect_to :hack &#187; General</title>
	<atom:link href="http://blog.coderubik.com/category/general/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.coderubik.com</link>
	<description>Thoughts on Ruby on Rails and Facebook development</description>
	<lastBuildDate>Thu, 07 Apr 2011 21:49:38 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Make Paypal PDF invoices with Payday</title>
		<link>http://blog.coderubik.com/2011/04/make-paypal-pdf-invoices-with-payday/</link>
		<comments>http://blog.coderubik.com/2011/04/make-paypal-pdf-invoices-with-payday/#comments</comments>
		<pubDate>Thu, 07 Apr 2011 21:49:38 +0000</pubDate>
		<dc:creator>Pierre Olivier Martel</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://blog.coderubik.com/?p=197</guid>
		<description><![CDATA[A lot of small web applications use Paypal as their primary gateway for accepting payments. Paypal takes care of the payment transactions for your application and sends the customer back to your site once the payment done. The only thing Paypal doesn&#8217;t do is proper invoicing. It sends confirmation emails with the transaction details but many [...]]]></description>
			<content:encoded><![CDATA[<p>A lot of small web applications use <a href="http://paypal.com">Paypal</a> as their primary gateway for accepting payments. Paypal takes care of the payment transactions for your application and sends the customer back to your site once the payment done. The only thing Paypal doesn&#8217;t do is proper invoicing. It sends confirmation emails with the transaction details but many corporate customers require a well-formatted PDF invoice as a proof or purchase.</p>
<p><a href="https://github.com/commondream/payday">Payday</a> is a Ruby gem that will help you create simple invoices. It&#8217;s a generic PDF invoicing library and as I will show you in this tutorial, it can be easily used to help you create invoices from Paypal transactions.</p>
<p>First thing to do, add the gem to your Gemfile :</p>
<pre class="brush: ruby; title: ; notranslate">gem &quot;payday&quot;</pre>
<p>Next, you can create a rails initializer file with your company infos :</p>
<pre class="brush: ruby; title: ; notranslate">
# /config/initializers/payday.rb
Payday::Config.default.invoice_logo = &quot;#{Rails.root}/public/images/logo.png&quot;
Payday::Config.default.company_name = &quot;My Company inc.&quot;
Payday::Config.default.company_details = &quot;100 Sunset Blvd\nHollywood\nUnited States\ninfo@mycompany.com&quot;
</pre>
<p>When a client makes a purchase on Paypal, you can configure your account to receive Instant Payment Notifications (IPN). I save each transaction in a Payment model and dump the paypal IPN request params in a serialized hash called paypal_params. This is the method from my model class I use to generate the invoice :</p>
<pre class="brush: ruby; title: ; notranslate">
# app/models/payment.rb
serialize :paypal_params

def generate_pdf_invoice
  invoice = Payday::Invoice.new(
    :invoice_number =&gt; paypal_params['invoice'],
    :currency =&gt; paypal_params['mc_currency'])
  invoice.paid_at = invoice.due_at = created_at.to_date
  invoice.bill_to = invoice.ship_to = paypal_params.slice(
    'address_name', 'address_street', 'address_city',
    'address_zip', 'address_country').values.join(&quot;\n&quot;)
  invoice.line_items &lt;&lt; Payday::LineItem.new(
    :price =&gt; paypal_params['mc_gross'],
    :quantity =&gt; 1,
    :description =&gt; paypal_params['item_name'])
  invoice.notes = &quot;Thank you for your purchase!&quot;
  invoice.render_pdf
end
</pre>
<p>Obviously, you will want to adjust this code to fit what you are selling. In my case, there is always only one line item in my transactions.</p>
<p>Finally, I make the invoice downloadable from the user account page. The controller method works like this :</p>
<pre class="brush: ruby; title: ; notranslate">
# app/controllers/payments_controller.rb
def pdf_invoice
  payment = Payment.find_by_tx_id! params[:id]
  respond_to do |format|
    format.pdf do
      send_data payment.generate_pdf_invoice,
        :filename =&gt; payment.invoice_filename,
        :type =&gt; &quot;application/pdf&quot;  , :disposition =&gt; &quot;inline&quot;
    end
  end
end
</pre>
<p>Again, you will probably have to adjust this method for your own needs. Don&#8217;t forget to add the pdf mime type to the mime_types.rb initializer :</p>
<pre class="brush: ruby; title: ; notranslate">
# /config/initializers/mime_types.rb
Mime::Type.register 'application/pdf', :pdf
</pre>
<p>There&#8217;s a lot more you can do with Payday. It supports I18n and it integrates well with ActiveRecord. I encourage you to take a look at the <a href="https://github.com/commondream/payday">readme on github</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.coderubik.com/2011/04/make-paypal-pdf-invoices-with-payday/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Display a Google Map with Rails</title>
		<link>http://blog.coderubik.com/2009/10/display-a-google-map-in-rails/</link>
		<comments>http://blog.coderubik.com/2009/10/display-a-google-map-in-rails/#comments</comments>
		<pubDate>Sun, 18 Oct 2009 13:07:28 +0000</pubDate>
		<dc:creator>Pierre Olivier Martel</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://modelix.net/?p=137</guid>
		<description><![CDATA[In my last article on geopositioning with Rails and Google maps, we saw how to use the YM4R/GM plugin to find and store the longitude/latitude of an address using the Google Maps api. With these informations, we can now display the map to the user. We’ll see how to do this in three easy steps. [...]]]></description>
			<content:encoded><![CDATA[<p>In <a href="/2009/10/rails-geopositioning-with-google-maps/">my last article on geopositioning with Rails and Google maps</a>, we saw how to use the <a href="http://ym4r.rubyforge.org/"><span class="caps">YM4R</span>/GM plugin</a> to find and store the longitude/latitude of an address using the Google Maps api. With these informations, we can now display the map to the user. We’ll see how to do this in three easy steps.</p>
<h2>1. Prepare the map in your model</h2>
<p>In your <code>Geolocation</code> model, start by adding this snippet of code which will initialize your map.</p>
<pre class="prettyprint rb"><code>def map
  @map ||= prepare_map
end

def mapped?
  latitude &amp;&amp; longitude
end

def coordinates
  [latitude, longitude]
end

private

def prepare_map
  return unless mapped?
  returning GMap.new("gmap") do |map|
    map.control_init(:large_map =&gt; true, :map_type =&gt; true)
    map.center_zoom_init(coordinates, 15) # Set the center and zoo level
    map.overlay_init(GMarker.new(coordinates))
  end
end
</code></pre>
<p>The important method here is <code>prepare_map</code>. What it does is create a new map centered at the given coordinates. The <code>overlay_init</code> method sets a marker at the coordinates position. This is a basic vanilla map initialization. You might want to read the <a href="http://ym4r.rubyforge.org/ym4r_gm-doc/"><span class="caps">YM4R </span>api</a> for more options like adding an info window or multiple markers.</p>
<h2>2. Call it from your controller</h2>
<p>In our controller, we will set the <code>@map</code> variable to make it accessible in our view :</p>
<pre class="prettyprint rb"><code>@map = customer.geolocation.map</code></pre>
<h2>3. Display the map in your view</h2>
<p>You will need this snippet of code in the <code>header</code> section of your document to do the proper javascript imports and initializations :</p>
<pre class="prettyprint rb"><code>= GMap.header
= @map.to_html
</code></pre>
<p>And in the body of your view, where you want to display the map, simply add :</p>
<pre class="prettyprint rb"><code>@map.div(:width =&gt; 600, :height =&gt; 400)</code></pre>
<p>This last line will generate a div with the id “gmap” (or whatever name you set in the <code>GMap.new</code> function). I find it’s cleaner to just set the width an height through <span class="caps">CSS.</span></p>
<h2>4. Adding complexity</h2>
<p>This technique will only work if you display only one map on the page. The map needs to be visible on page load to be properly displayed. But what if there is multiple maps you want to display on the same page? And what if you want to show them in overlay popups? You probably don’t want to initialize them all on page load since it will freeze the client browser. This will require some javscript hacking. I will show you how to do that next week!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.coderubik.com/2009/10/display-a-google-map-in-rails/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->
