<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0"><channel><description>I’m a programmer who rants and raves about SEO, social media, web programming. If you are in the same field as me, read! I have tutorials.

Bitcoin: 131JuNLWCdy6D2EQDkGeRGkd2FtyU3Uzie</description><title>Ben Morgan I/O</title><generator>Tumblr (3.0; @benmorganio)</generator><link>http://blog.benmorgan.io/</link><item><title>Dear Spree, We Broke Up</title><description>&lt;p&gt;&lt;a href="https://github.com/spree/spree/pull/6918" target="_blank"&gt;https://github.com/spree/spree/pull/6918&lt;/a&gt;&lt;br/&gt;&lt;/p&gt;&lt;p&gt;I’m sorry Spree. Its not you, its me. I’m not the right developer for you. Not a lot of developers are the right ones for you. But, maybe you’ve found one. And that’s great. I’m dating this new girl. Her names Solidus and we get a long a lot better. I’m sorry Spree, but we broke up.&lt;/p&gt;&lt;p&gt;I hope that the future is bright for you. I’m happy you’re receiving maintenance and that the future looks brighter for you. I hope you find happiness in the future.&lt;/p&gt;&lt;p&gt;I’m writing this letter because I need you to know that there’s a wound in my heart. A while back, a piece of my heart had your name on it, Spree. With FirstData coming into our relationship, we knew things had to end and we needed to both move on. This letter is so that we can move on from each other.&lt;/p&gt;&lt;p&gt;To help this process, I’m using &lt;a href="https://www.youtube.com/watch?v=O8hQVlRgFlU" target="_blank"&gt;George Lucas’s three commandments&lt;/a&gt; of break ups.&lt;/p&gt;&lt;p&gt;1. I will not phone call Spree.&lt;br/&gt;2. I will not drive by Spree’s house and see what she’s doing.&lt;br/&gt;3. I will not show up at her coffee shop.&lt;br/&gt;&lt;/p&gt;&lt;p&gt;I’m sorry Spree, but we broke up. Not watching. Unstaring. And most importantly: we can’t fork anymore.&lt;/p&gt;</description><link>http://blog.benmorgan.io/post/137809777646</link><guid>http://blog.benmorgan.io/post/137809777646</guid><pubDate>Fri, 22 Jan 2016 07:38:02 -0500</pubDate><category>breakup</category><category>spree</category><category>spreecommerce</category></item><item><title>From Spree to Solidus</title><description>&lt;p&gt;A long time ago Spree was the go to ecommerce framework for Rails. For those who don&amp;rsquo;t know, Spree had a &lt;em&gt;lot&lt;/em&gt; of bugs. But no one really beat the contributors up on it. Everyone knew: ecommerce is &lt;strong&gt;hard&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Over time, the contributors started to disappear. Their Github said they still worked for Spreecommerce, but they were gone. No contributions. Where did they go?&lt;/p&gt;

&lt;p&gt;Then Ryan Bigg quit.&lt;/p&gt;

&lt;p&gt;You could feel the cogs turning inside of Spreecommerce. Should we support Spree or keep supporting SpreeHub? Then boom! SpreeHub was renamed to Wombat with an all new admin. Now we know what everyone was working on. Now we knew where Spreecommerce was investing in.&lt;/p&gt;

&lt;p&gt;We hoped that once Wombat was doing good, they&amp;rsquo;d focus more time back on Spree. Unfortunately, this never paid off for the Spree community. Spree only had one core contributor and you could tell he was working on the project part time. The most popular ecommerce framework was being neglected.&lt;/p&gt;

&lt;p&gt;And so, the community wanted access to the &amp;ldquo;merge&amp;rdquo; button. They weren&amp;rsquo;t getting it. You &lt;em&gt;had&lt;/em&gt; to work for Spreecommerce. So, what did the unsung heroes of Spree do? They forked it.&lt;/p&gt;

&lt;p&gt;Tons of tiny bug fixes enter Spree. Tons of new and amazing features ended up in Solidus. Solidus was even fix long outstanding bugs. They were on point.&lt;/p&gt;

&lt;p&gt;I&amp;rsquo;m moving to Solidus, are you?&lt;/p&gt;</description><link>http://blog.benmorgan.io/post/131707149271</link><guid>http://blog.benmorgan.io/post/131707149271</guid><pubDate>Thu, 22 Oct 2015 17:35:43 -0400</pubDate><category>solidus spree ecommerce rails</category></item><item><title>Relying on Blog Posts for Tech Information</title><description>&lt;p&gt;Sometimes, when someone is making a recommendation on why they think something is a best practice, they’ll reference a blog post. What’s great about a blog post is that there’s people (like me) that will explain simply why something is a good implementation and why you should do it too.&lt;/p&gt;&lt;p&gt;But here’s the thing, if you look into my blog archive, you’ll discover that you should store Twitter configuration in a global variable. (I broke a production app by implementing that. Worst part: its recommended on the twitter ruby client readme&amp;hellip;) I have other _bad_ recommendations as well that I’m sure even a junior dev can find. Don’t trust me.&lt;/p&gt;&lt;p&gt;Oh, but wait, I’m a good dev. I’m a core contributor to Spree! I have to have at least some idea how to program. I mean, I do help out on the biggest ecommerce framework for ruby on rails.&lt;/p&gt;&lt;p&gt;So, why are blog posts bad references? They aren’t peer reviewed and they don’t contain other peoples opinions. You might get another persons opinion, but that’s only if you check the comments; if they have comments turned on and guess what: I don’t.&lt;/p&gt;&lt;p&gt;What are some reliable resources? Popular Stackoverflow questions with tons of activity.&lt;/p&gt;&lt;p&gt;Actually, nvm. I’ve changed my mind. This is now a blog post that is here to be-all-end-all to the discussion of what is a valid reference. Blog posts (especially the ones where comments are turned off) are now the go to reference.&lt;/p&gt;</description><link>http://blog.benmorgan.io/post/130644280561</link><guid>http://blog.benmorgan.io/post/130644280561</guid><pubDate>Tue, 06 Oct 2015 18:40:36 -0400</pubDate></item><item><title>Sir, i am getting a compatibility error for spree auth devise gem while installing spree using your method.  Could you please tell me which ruby/rails version should i use?</title><description>&lt;p&gt;Which Spree version are you using? 3.0 is for rails 4.2 and 2.3/2.4 is for rails 4.1. If you’re getting an incompatibility error, maybe also point spree_auth_devise to the same gem version.&lt;/p&gt;</description><link>http://blog.benmorgan.io/post/126485768606</link><guid>http://blog.benmorgan.io/post/126485768606</guid><pubDate>Wed, 12 Aug 2015 01:19:42 -0400</pubDate></item><item><title>Hey Ben, we are contemplating using Spree for our web presence/e-commerce. We would like to benefit from a world filled with inexpensive high-quality themes. How easy is it to get any random theme designed for Bootstrap to work with Spree? Thx! Thorsten</title><description>&lt;p&gt;They should be just the CSS or SCSS/LESS files. Preferably SCSS. If its just that, then you can plug it into a default spree storefront and customize it from there.&lt;/p&gt;</description><link>http://blog.benmorgan.io/post/126485697031</link><guid>http://blog.benmorgan.io/post/126485697031</guid><pubDate>Wed, 12 Aug 2015 01:18:36 -0400</pubDate></item><item><title>hi Ben.  i am RoR programmer how to integrate wombat with spree</title><description>&lt;p&gt;Would love to help you how, but you’re an anon.&lt;/p&gt;</description><link>http://blog.benmorgan.io/post/118402050261</link><guid>http://blog.benmorgan.io/post/118402050261</guid><pubDate>Thu, 07 May 2015 20:07:42 -0400</pubDate></item><item><title>Hi ben , i need some support on a spreecommerce project let me know if u have time</title><description>&lt;p&gt;I’d love to help you out Mr. Anon, but let me know when you’re free to not be anonymous.&lt;/p&gt;</description><link>http://blog.benmorgan.io/post/117926619811</link><guid>http://blog.benmorgan.io/post/117926619811</guid><pubDate>Sat, 02 May 2015 05:55:36 -0400</pubDate></item><item><title>Spree's API</title><description>&lt;p&gt;A long time ago, the issues inside of Spree used to be either silly questions (usually by me) or noting another shipment/adjustment bug. You don&amp;rsquo;t see that anymore. You see serious performance issues in edge areas or pull requests for new features or to deprecate some not so ideal features.&lt;/p&gt;

&lt;p&gt;Spree now has over 6000 stars, 350 people watching, and over 2800 forks. Spree is popular. GoDaddy is building their &amp;ldquo;Shopify killer&amp;rdquo; with it and I have no doubt they&amp;rsquo;ll crush them. They think about marketing and disrupting the media enough to make them, well, far more noticable than the polite Canadian ads from Shopify.&lt;/p&gt;

&lt;p&gt;Shopify also has limitations. And people &lt;em&gt;want&lt;/em&gt; and &lt;em&gt;need&lt;/em&gt; to move off. ShoeMe is on Shopify and they&amp;rsquo;ve purchased an already established .NET storefront to move everything over to. Its not uncommon for me to check my inbox and read an email from someone wanting to migrate from Shopify. GoDaddy is and has created a marketplace platform, integrated liquid, and built a Rails application structure that will make Shopify rethink its tech stack and its features.&lt;/p&gt;

&lt;p&gt;Its also great for the Spree community because of the publicity this gives Spree. And Spree is getting popular. Very very popular.&lt;/p&gt;

&lt;p&gt;Its also insanely complex. You have around ~75 tables in your DB with Spree and over 100 models for your business logic. However, this is expected. This &lt;em&gt;is&lt;/em&gt; ecommerce. If you think you can make a store with no more than 20 models, I&amp;rsquo;ll point you to the door and if I&amp;rsquo;m in a good mood, hold it open for you.&lt;/p&gt;

&lt;p&gt;If you think that you can walk into ecommerce and &lt;em&gt;modularize&lt;/em&gt; the functionality, lets sit down and talk. The fact that you can walk up and say &amp;ldquo;Hey, this is big and its messy and its world changing. How to do we contain it and make things easier for people?&amp;rdquo; then you might find a place in ecommerce in general.&lt;/p&gt;

&lt;p&gt;The web in a whole is moving to an API driven ecosystem. I don&amp;rsquo;t even use the spree_frontend. I just bundle with the spree_backend and I get the spree_api and the spree_core automatically. This means Spree storefronts are using Backbone, Angular, and Ember. I&amp;rsquo;m a plus one for Ember due to its convention over configuration. Backbone also has its place for legacy and wider support. Its minimal, its easier to learn, but I also think its more for the experienced to ensure the application follows standard best practices and conventions as well as ensuring its supportive of legacy. Angular seems to be doing its own thing by making antipractices best practices and lying out its teeth in its marketing (you only need angular.js! as 1 dependency, we follow MV*, we&amp;rsquo;re really good with data. I spent more time trying to work around their BS than anything else. IMO don&amp;rsquo;t pick a framework that&amp;rsquo;s marketed by a company. There&amp;rsquo;s been too much lying to actually get work done. And too many white promises.)&lt;/p&gt;

&lt;p&gt;If you&amp;rsquo;re building your next Spree store with Ember, you&amp;rsquo;ll probably be wanting an API to work with. Right now, you have to sorta build your own. I&amp;rsquo;m hoping I can set time away to get an Ember friendly Spree API built for 4.0. Work has already started since 3-0-stable was created.&lt;/p&gt;

&lt;p&gt;Making a single page storefront is hard. You&amp;rsquo;ll have enourmous amounts of data and a &lt;em&gt;lot&lt;/em&gt; of components to manage. I highly recommend Ember for the job. It Rails developer-ish friendly. Its also great for people moving from Backbone since it has the same dependencies. Its the type of framework I see surviving the long battle as people discover its doing all the right things and it doesn&amp;rsquo;t sit and lie to its users (read: angular).&lt;/p&gt;

&lt;p&gt;Lets talk about JSON. You know when you do an API request and you want to get your data back? That&amp;rsquo;s the first thing that&amp;rsquo;s changing in Spree. I think many people can agree that Spree needs a consistent and established way for serializing the JSON. Spree is currently using Rabl and to be frank, it needs to go. Rabl has not been supportive of multiple rails applications. So, if you&amp;rsquo;re trying to load a rabl template in Spree from your main application, its not going to work. You just lost all the benefits and you might as well build your own API.&lt;/p&gt;

&lt;p&gt;The API in Spree is being switched from Rabl to Active Model Serializers. Caching is going to be a neccessity so we won&amp;rsquo;t be using 0.9. 0.8 is currently being used and when 0.10 comes out, Spree will switch to that ASAP. I&amp;rsquo;m looking forward to AMS 0.10.&lt;/p&gt;

&lt;p&gt;After the AMS change and all the rabl templates have been deprecated, work can be started on changing Spree&amp;rsquo;s API up to be more Ember friendly. If it can work on Ember, it can work anywhere, mainly because Ember inforces best practices and if the JSON can be rendered using the best practices, it shouldn&amp;rsquo;t matter if you&amp;rsquo;re on Backbone, (Angular,) Knockout, or Kendo.&lt;/p&gt;

&lt;p&gt;The aim of this blog post was to communicate three things: (1) Spree is growing and with that, its API is going to be changing, (2) more storefronts are using JS frameworks so the API needs to shape up where it may be lacking, (3) people need to serializer JSON in ruby, AMS is going to support that and that&amp;rsquo;s also a reason for the change.&lt;/p&gt;

&lt;hr&gt;&lt;ul&gt;&lt;li&gt;My notes on Angular are &lt;em&gt;my&lt;/em&gt; opinion. I still work with it and I&amp;rsquo;m enthusiastic that they might treat their users (read: me) nicer. I still use it on a lot of Rails applications. Its my opinion.&lt;/li&gt;
&lt;/ul&gt;</description><link>http://blog.benmorgan.io/post/112355974561</link><guid>http://blog.benmorgan.io/post/112355974561</guid><pubDate>Sat, 28 Feb 2015 18:16:30 -0500</pubDate></item><item><title>Raptor (Passenger 5) with Ruby on Rails</title><description>&lt;p&gt;A while back I remember hearing all the buzz about Ruby Raptor and it was later disclosed that it was actually the fifth version of Phusion Passenger.&lt;/p&gt;

&lt;p&gt;For my Rails projects, I&amp;rsquo;m a user of either Thin or Puma. When I head over to a Spree application using Puma, this was what I received in performance terms:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;$ wrk -t10 -c10 -d20s http://localhost:3000
Running 20s test @ http://localhost:3000
  10 threads and 10 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency    10.22s    40.55ms  10.31s    77.78%
    Req/Sec     0.00      0.00     0.00    100.00%
  18 requests in 20.03s, 220.84KB read
  Socket errors: connect 0, read 0, write 0, timeout 82
Requests/sec:      0.90
Transfer/sec:     11.02KB
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Then I decided to try out Raptor with Spree. I began with a &lt;code&gt;gem install passenger&lt;/code&gt; and ran &lt;code&gt;passenger start&lt;/code&gt;. This was the output:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;$ passenger -v
Phusion Passenger version 4.0.58

$ wrk -t10 -c10 -d20s http://localhost:3000
Running 20s test @ http://localhost:3000
  10 threads and 10 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency     6.73s   745.85ms   7.50s    50.00%
    Req/Sec     0.00      0.00     0.00    100.00%
  22 requests in 20.03s, 272.91KB read
  Socket errors: connect 0, read 0, write 0, timeout 75
Requests/sec:      1.10
Transfer/sec:     13.63KB
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;As you can see, Passenger 4 is already faster than Puma. How about we get going with Raptor and see how it competes?&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;$ gem uninstall passenger
Successfully uninstalled passenger-4.0.58

$ gem install passenger --pre

$ passenger -v
Phusion Passenger version 5.0.0.beta2

$ wrk -t10 -c10 -d20s http://localhost:8080
Running 20s test @ http://localhost:8080
  10 threads and 10 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency     5.60s     1.06s    6.50s    85.71%
    Req/Sec     0.00      0.00     0.00    100.00%
  31 requests in 20.03s, 379.66KB read
  Socket errors: connect 0, read 0, write 0, timeout 64
Requests/sec:      1.55
Transfer/sec:     18.95KB
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;You&amp;rsquo;ll notice that I used port 8080 instead of 3000. This seems to be a passenger bug from my understanding. I kept receiving an error stating tht port 3000 was already in use, so I decided to switch it over to 8080 and everything was working again.&lt;/p&gt;

&lt;p&gt;I&amp;rsquo;m pretty happy with these performance improvements.&lt;/p&gt;

&lt;p&gt;Some things that I would like from Raptor is some better documentation on getting started and at least letting us know that you don&amp;rsquo;t need Nginx running. They also need to make their documentation a lot more readable.&lt;/p&gt;

&lt;p&gt;All in all, I can see passenger possibly being used in production, but the difficulty of getting it to work (or at least discovering &lt;code&gt;passenger start&lt;/code&gt;) may be a hurdle.&lt;/p&gt;

&lt;p&gt;My recommendation:&lt;/p&gt;

&lt;p&gt;Stick with Thin or Puma until Passenger makes a deeper commitment in helping simplify their get started page. Otherwise, your app/company may find themselves in some sticky situations, digging through their unorganized, but plentiful docs for a single command that you should have known about from the beginning.&lt;/p&gt;

&lt;p&gt;Thin and Puma can both be booted from the very start with a &lt;code&gt;rails s&lt;/code&gt;. Passenger is not as friendly.&lt;/p&gt;</description><link>http://blog.benmorgan.io/post/110502101441</link><guid>http://blog.benmorgan.io/post/110502101441</guid><pubDate>Sun, 08 Feb 2015 21:58:02 -0500</pubDate></item><item><title>Building Large Rails Applications: The Comedians Take</title><description>&lt;p&gt;I&amp;rsquo;ve been working on large rails applications ever since I started learning. I remember being recruited at a start up and sitting and looking at a rails app with no less than 100 models. Phew boy.&lt;/p&gt;
&lt;p&gt;You don&amp;rsquo;t even know MVC yet, and you&amp;rsquo;re looking at an application that even the best will be biting their teeth on. Its scary.&lt;/p&gt;
&lt;p&gt;And I&amp;rsquo;ve been doing this for a while now. Working with large Rails applications. Non-stop. All Spree apps. All of them have more than 100 models. I like to think that a small rails app is one with a single digit models (1 to 9). Medium apps tend to extend into the double digits and stops half way (11 to ~50), BUT you can certainly argue that a large rails app starts to form at around 30 or 40. However, you can argue that the excess 20 models start to become autonomous with the application and their complexity might be more from rails &amp;ldquo;imperative&amp;rdquo; conventions, rather than from existing for complex reasons. These could be HABTM models or abstract models. You ge the idea. They may exist only to serve a very basic need, not to add new features to the app.&lt;/p&gt;
&lt;p&gt;And then there&amp;rsquo;s the large rails apps. These come in at around 50 to 100 models. They start to become burdened with complexity and may take months to get a feel for. This is not where Spree falls into.&lt;/p&gt;
&lt;p&gt;When you start to reach a rails application with more than 100 models, you know you&amp;rsquo;re in for a ride. The thoughts of abstraction and &amp;ldquo;feature removal&amp;rdquo; start to fill your mind. How do you handle this? You make effectively bad decisions of course!&lt;/p&gt;
&lt;h1&gt;Goodbye shoulda&lt;/h1&gt;
&lt;p&gt;Your behemoth doesn&amp;rsquo;t need simple line by line testing. You can trust me on that. Things are so interconnected that a simple change will cause your app to crash. Shoulda matchers start to add a burden and from this, you aren&amp;rsquo;t writing unit tests anymore, you&amp;rsquo;re writing more and more complex BDD features.&lt;/p&gt;
&lt;p&gt;(I&amp;rsquo;d like to note that this is where BDD starts to shine is in the &amp;ldquo;larger than life&amp;rdquo; rails apps. BDD might take 2 seconds to cover the model to controller to view to the god-knows-what-else-got-added and the same for unit tests might take 5 seconds to cover. Constantly starting and stopping as it moves through. the BDD doesn&amp;rsquo;t stop. It just washes over your code. Dropping its TDD coverage red and green slime wherever it goes.)&lt;/p&gt;
&lt;h1&gt;The Namespacing of the Rails App&lt;/h1&gt;
&lt;p&gt;Bet you never thought this was going to happen. You have a nice and lovely rais app. You&amp;rsquo;ve called it &lt;code&gt;Articlz&lt;/code&gt;. That&amp;rsquo;s a nice name. Now be prepared to add a &lt;code&gt;Articlz::Base&lt;/code&gt; model prefixing all your tables with &lt;code&gt;"articlz_"&lt;/code&gt;. Get ready for some serious namespacing issues &amp;gt;:-). Instead of making a &lt;code&gt;Post&lt;/code&gt; model, you&amp;rsquo;re making an &lt;code&gt;Articlz::Post&lt;/code&gt; model. It seems silling to namespace your own application, but guess what, it happens.&lt;/p&gt;
&lt;h1&gt;The Monthly Gemfile Refactor&lt;/h1&gt;
&lt;p&gt;Its actually quite common for a Gemfile to get bigger than 100 lines, but 500? Oh yeah, you&amp;rsquo;re going to want some organization. You learn to make you&amp;rsquo;re own meta gems.&lt;/p&gt;
&lt;h1&gt;The I-&amp;lt;3-Hexagonal-Architecture&lt;/h1&gt;
&lt;p&gt;Nope. Still don&amp;rsquo;t love it. But your app is so big, you have a HABTM merge belonging to eight models. At some point, you start to use hexagonal here and there. Biting you teeth as you try to keep to MVC. Its more of an unfortinate and unpleasent experience than anything else. You turn them as &amp;ldquo;exceptions to the rails-way&amp;rdquo;, but you know you could have done better.&lt;/p&gt;
&lt;h1&gt;The CI Server Meltdown&lt;/h1&gt;
&lt;p&gt;Your app is so big, you don&amp;rsquo;t just use some CI server like CircleCI. You&amp;rsquo;re to the point that any Github merge goes through at least 5 CIs. And if you&amp;rsquo;ve ever used CircleCI, you might have ~5 test suites to run inside of it&amp;hellip; Page&amp;hellip; by&amp;hellip; page&amp;hellip;.&lt;/p&gt;
&lt;h1&gt;And then God said, let there be linting.&lt;/h1&gt;
&lt;p&gt;You can&amp;rsquo;t stand the 250,000 lines of crap. You&amp;rsquo;ve got rubocop running constantly in the one directory you&amp;rsquo;re working on not by Guard, but from some ruby script. Its customized to your development hidden from everyone through your git ignore. You&amp;rsquo;re still Hounded.&lt;/p&gt;
&lt;h1&gt;The hiding-systems-languages-in-your-lib-dir&lt;/h1&gt;
&lt;p&gt;You need your app to actually perform as the loading of 10 includes through rails is taking 7 seconds. You tell yourself you could just cache it, but you don&amp;rsquo;t want to have to cache on development (even though you&amp;rsquo;re already doing it). You end up doing a &lt;code&gt;cd lib &amp;amp;&amp;amp; cargo new rust --bin&lt;/code&gt; and add to the readme under some &amp;ldquo;quick install&amp;rdquo; that also lists installations via Bundler, Bower, npm, and some other utilities in the kitchen sink:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Rust is also used to allow for faster DB queries and joins/includes.
We chose it over Go because it has a package manager (Cargo).
This way we don't have to check in vendor code and not accidentally
make our app even bigger...
Be sure to check in the compiled rust code BTW.
&lt;/code&gt;&lt;/pre&gt;
&lt;h1&gt;The Lets-Find-Waldos-View-Game&lt;/h1&gt;
&lt;p&gt;Someone had a great idea of rendering views and compiling them into that god aweful JS language. You&amp;rsquo;re jumping from views, to assets/javascripts, to public, and for some reason even vendor/assets just to find some HTML that really should be in the views directory. You think it only happens once. You open the views page, there&amp;rsquo;s one file called &lt;code&gt;index.html.haml&lt;/code&gt;. Two lines of &amp;ldquo;HTML&amp;rdquo; and they go like this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;#app-name
  %div{"ng-view" =&amp;gt; true}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Then you realize it could be refactored to one line.&lt;/p&gt;
&lt;p&gt;You end the day going, &lt;strong&gt;Where&amp;rsquo;s 99% of the HTML&lt;/strong&gt;? Angular Templates&amp;hellip;&lt;/p&gt;
&lt;h1&gt;Conclusion&lt;/h1&gt;
&lt;p&gt;If you have anything to add to this blog post about behemoth rails apps and the new/modern (dumb, stupid, and poorly thought out) conventions used by the &amp;ldquo;Rails&amp;rdquo; developers that don&amp;rsquo;t actually use the Rails-Way, I&amp;rsquo;d love to add it in :)&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Disclaimer&lt;/strong&gt;: This blog post is meant for humour. Its not meant to degrade any rails developers or JS developers. Some of these points are actually quite valid and you can actually find quite a bit of meaningfullness from them. Large apps are generally difficult to maintain and those that do manage them do deserve respect. Especially Spree developers :)&lt;/p&gt;</description><link>http://blog.benmorgan.io/post/109244315696</link><guid>http://blog.benmorgan.io/post/109244315696</guid><pubDate>Mon, 26 Jan 2015 18:28:36 -0500</pubDate></item><item><title>hi Morgan, Glad to meet you, may i seek your guidance regarding spree platform, and other ecommerce platforms,thanks,Rao,india</title><description>&lt;p&gt;I hope my blog posts are helpful. Spree is just a rails application. Quite often the best way to work with Spree is to simple understand that its just another Rails app. I don’t actually have a knowledge base of other ecommerce platforms besides Spree.&lt;/p&gt;</description><link>http://blog.benmorgan.io/post/108329762861</link><guid>http://blog.benmorgan.io/post/108329762861</guid><pubDate>Sat, 17 Jan 2015 02:39:40 -0500</pubDate></item><item><title>Is it possible to enhance spree to allow vendor to login in backend and add their own products?</title><description>&lt;p&gt;You could in theory, but I wouldn’t recommend it. I would recommend creating a new model (MyApp::Vendor) and let it have many products. OR you could assume that all users can have their own “marketplaces”. Basically saying a User has one Marketplace and that Marketplace has many products. That would actually be pretty easy work. Once you’ve built a simple CRUD where a user can list their products, you can start to think about shipments and promotions.&lt;/p&gt;
&lt;p&gt;If you truly want to let users access the Spree Admin dashboard, you should take a look at Spree::Ability and Spree::Role.&lt;/p&gt;
&lt;p&gt;Hope this helps :)&lt;/p&gt;</description><link>http://blog.benmorgan.io/post/108329649061</link><guid>http://blog.benmorgan.io/post/108329649061</guid><pubDate>Sat, 17 Jan 2015 02:37:17 -0500</pubDate></item><item><title>Customizing Spree: Some Best Practices</title><description>&lt;p&gt;In this blog post, I&amp;rsquo;m going to go over some best practices that I follow with Spree. They come in very handy as you customize it and as your application grows.&lt;/p&gt;
&lt;h2&gt;Namespace Everything: This is not as simple as you might think&amp;hellip;&lt;/h2&gt;
&lt;p&gt;Quite often I find myself &lt;code&gt;class_eval&lt;/code&gt;ing &lt;a href="https://github.com/spree/spree" target="_blank"&gt;Spree&lt;/a&gt;. I also find myself including extra Rails Engines into the application such as &lt;a href="https://github.com/magiclabs/alchemy_cms" target="_blank"&gt;AlchemyCMS&lt;/a&gt; and &lt;a href="https://github.com/radar/forem" target="_blank"&gt;Forem&lt;/a&gt;. Its usually a Spree + Alchemy merge. This can lead to a lot of folders. When I open up the models folder I tend to get this as a list: alchemy, concerns, spree, .keep.&lt;/p&gt;
&lt;p&gt;The .keep is a file for version control. Please delete these as you build your application. I find it a best practice to remove .keeps when their presence is no longer needed. I&amp;rsquo;m also a really good developer, so I know the file structure by heart. Since I can autonomously put files in the correct folder by nature, I simply delete all .keeps and their folders in a rails app. After I&amp;rsquo;ve removed all the empty folders, I can immediately see how small or large an application is and what they&amp;rsquo;re doing and what they are not doing. Very nice visual trick; I&amp;rsquo;m a visual learner.&lt;/p&gt;
&lt;p&gt;When I open the spree folder in a model I usually see a mix of models and decorators. Decorators &lt;em&gt;should&lt;/em&gt; go into the models folder. They are there to mimic and reopen a current model. But, you shouldn&amp;rsquo;t place new models inside of a Rails Engine.&lt;/p&gt;
&lt;p&gt;Let&amp;rsquo;s say you decorate the products model from Spree as so:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Spree::Product.class_eval do
  belongs_to :vendor, class_name: Spree::Vendor
end
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And then you have your vendor model as so:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;module Spree
  class Vendor &amp;lt; Spree::Base
    has_many :products, class_name: Spree::Product
  end
end
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I think its great that the product model is being decorated inside of the models folder, but there&amp;rsquo;s something wrong with the vendor model. You&amp;rsquo;re going to have a mix of decorators and models all at once, where you should only have those decorators inside of spree, not a new model. We need to put it somewhere else.&lt;/p&gt;
&lt;p&gt;Usually, this would mean that the developer would put it at the root of the models, making it &lt;code&gt;Vendor &amp;lt; Spree::Base; end&lt;/code&gt;, but again, I don&amp;rsquo;t think that&amp;rsquo;s right. The best solution is to actually make a namespace for your own application. Lets say your app is called &lt;code&gt;GroceryStore&lt;/code&gt;, then you should name your vendor model:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;module GroceryStore
  class Vendor &amp;lt; ::Spree::Base
  end
end
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This is much more organized and much more Railsie. You&amp;rsquo;ll notice that the &lt;code&gt;Spree::Base&lt;/code&gt; is being inherited. To remove this, we&amp;rsquo;ll make our own base model and have it include &lt;code&gt;Spree::Base&lt;/code&gt; naturally.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;module GroceryStore
  class Base &amp;lt; ActiveRecord::Base
    include ::Spree::Base

    self.abstract_class = true
  end
end
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;A note on concerns:&lt;/strong&gt; If you&amp;rsquo;re making a new concern, it goes into your application namespace (ex: `GroceryStore::MyNewConcern`). If you&amp;rsquo;re decorating a concern, that goes into the respective engines namespace.&lt;/p&gt;
&lt;p&gt;I highly recommend namespacing &lt;em&gt;everything&lt;/em&gt;. Especially if you are going to have to be working with one or two or even three Rails Engines.&lt;/p&gt;
&lt;h2&gt;Deface: No Laundry Lists&lt;/h2&gt;
&lt;p&gt;I remember working on my first Spree application and phew boy, were the overrides just a laundry list! Basically, &lt;em&gt;you should not be coding your overrides like its 2003&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/spree-contrib/spree-multi-domain/tree/master/app/overrides" target="_blank"&gt;This is an example of a laundry list.&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/kinduff/spree_reffiliate/tree/master/app/overrides" target="_blank"&gt;This is an example of a clean overrides folder.&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Notice how in the latter one you can easily find what is and isn&amp;rsquo;t being overrided, but not in the first one? This is what I mean and its a best practice when it comes to deface. Your file structure in your overrides should match your views file structures. And your views file structure is dictated by Rails, not by you. So if you turn and say &amp;ldquo;Hey, what if I change the name of my index to home?&amp;rdquo; then we have some problems; you&amp;rsquo;re fired.&lt;/p&gt;
&lt;h2&gt;Use Before Actions&lt;/h2&gt;
&lt;p&gt;I can&amp;rsquo;t tell you how many times I see this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Spree::SomeController.class_eval do
  alias_method :orig_method_name, :method_name

  def method_name
    some_awesome_code
    that_does_something
    hey_there
    orig_method
  end
end
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This isn&amp;rsquo;t good code. This is code that goes against the Rails-Way. Please use &lt;code&gt;before_action&lt;/code&gt;s. Please. The corrent way is:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Spree::SomeController.class_eval do
  before_action :awesome_code, only: :method_name

  private

  def awesome_code
    some_awesome_code
    that_does_something
    hey_there
  end
end
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And that&amp;rsquo;s it. Also, please don&amp;rsquo;t use &lt;code&gt;orig_method&lt;/code&gt; or &lt;code&gt;old_method&lt;/code&gt; or whatever you can think up. Ruby already has the naming convention down and you should be using that and not your own. Its called &lt;code&gt;super&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;super&lt;/code&gt; won&amp;rsquo;t work in this case since we&amp;rsquo;re overwriting the method and not overriding it. Therefore, when you know you have to do that icky &lt;code&gt;alias_method&lt;/code&gt; trick to store the original method, I would actually rather you do this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Spree::SomeController.class_eval do
  alias_method :super_method_name, :method_name

  ...
end
&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Mailers&lt;/h2&gt;
&lt;p&gt;When creating mailers, I expect them to be completely overwritten due to the nature of some applications and of emails in general.&lt;/p&gt;
&lt;p&gt;I was once on a project where a team was using Ink. They used Mailchimps inliner to put the CSS inline and then commit the HTML. Don&amp;rsquo;t ever do this. Please to gosh don&amp;rsquo;t ever do this. Ever. Ever. Ever. You&amp;rsquo;ll dig your own hole faster via emails then anywhere else. This is a complete Rails antipattern in everything that Rails stands for.&lt;/p&gt;
&lt;p&gt;Due to this, I had to go out and create &lt;a href="https://github.com/BenMorganIO/blot" target="_blank"&gt;Blot&lt;/a&gt;. Blot is fantastic. I&amp;rsquo;ve been using it in all my emails and its just made everything so simple. It has a bit more work needed so that you don&amp;rsquo;t have to do &lt;code&gt;wrapper(class: 'wrapper')&lt;/code&gt;, but its already very mature as a solution to keep you from coding like its 1998. To inline your CSS, I would recommend using &lt;a href="https://github.com/fphilipe/premailer-rails" target="_blank"&gt;premailer-rails&lt;/a&gt;. (I would recommend to turn comment removal off since Ink uses comments to work with Outlook responsively.) There&amp;rsquo;s also a lot of work going into the &lt;a href="https://github.com/zurb/ink" target="_blank"&gt;Ink&lt;/a&gt; project. I highly recommend you check it out if you haven&amp;rsquo;t yet and use their CSS as a boilerplate.&lt;/p&gt;
&lt;h2&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;When you see something making a mess, take a step back and stop digging your hole. Follow the Rails-Way.&lt;/p&gt;
&lt;p&gt;Due to the enormous amount of anti-patterns that I see day in and day out, I have come to the realization that a book is needed to help train people for Spree.&lt;/p&gt;
&lt;p&gt;Spree is not for beginners. You should already feel comfortable in Rails before using Spree. This is the #1 reason for poor Spree applications and to change this, I&amp;rsquo;m writing a book.&lt;/p&gt;
&lt;p&gt;If you would like to contribute, please email me and then let me know. The more input and authors, the more we can help the community develop.&lt;/p&gt;</description><link>http://blog.benmorgan.io/post/102924399166</link><guid>http://blog.benmorgan.io/post/102924399166</guid><pubDate>Mon, 17 Nov 2014 21:27:00 -0500</pubDate><category>spree</category><category>spreebook</category><category>best practices</category><category>rails way</category><category>ruby on rails</category><category>ruby</category><category>rails</category><category>rails engines</category><category>deface</category><category>overrides</category><category>mvc</category><category>models</category><category>views</category><category>controllers</category></item><item><title>Adding Preferences to Spree 2.3</title><description>&lt;p&gt;If you checkout this &lt;a href="https://github.com/spree/spree/releases/tag/v2.3.0" target="_blank"&gt;CHANGELOG diff for the Spree 2.3.0 tag&lt;/a&gt; you&amp;rsquo;ll see that preferences were removed from all the models except for &lt;code&gt;Spree::Calculator&lt;/code&gt;, &lt;code&gt;Spree::PromotionRule&lt;/code&gt;, and &lt;code&gt;Spree::PaymentMethod&lt;/code&gt;. If you&amp;rsquo;re wanting to store some preferences information, I&amp;rsquo;ll show you how in this blog post.&lt;/p&gt;
&lt;p&gt;For our example, we&amp;rsquo;re going to assume that we have a store that requires us to collect the first and last name of a user. To do this, we&amp;rsquo;re going to have to add a new column to our user model.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;$ rails g migration add_preferences_to_spree_users
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Then, within your migration, you would add the new column and its rollback:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;class AddPreferencesToSpreeUsers &amp;lt; ActiveRecord::Migration
  def up
    add_column :spree_users, :preferences, :text
  end

  def down
    remove_column :spree_users, :preferences
  end
end
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;When I was first doing this, I thought that I would use &lt;code&gt;:hstore&lt;/code&gt; instead of &lt;code&gt;:text&lt;/code&gt;, but it turns out that they actually don&amp;rsquo;t store it within PG as JSON, just a textual form of some YAML. I can confirm this when I hit up the &lt;code&gt;rails c&lt;/code&gt; and investigate the &lt;code&gt;Spree::Calculator&lt;/code&gt; model:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;pry(main)&amp;gt; Spree::Calculator
=&amp;gt; Spree::Calculator(id: integer, type: string, calculable_id: integer, calculable_type: string, created_at: datetime, updated_at: datetime, preferences: text)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;As we can see, it is a text field that &lt;code&gt;:preferences&lt;/code&gt; gets stored as.&lt;/p&gt;
&lt;p&gt;Once you have this code, we need to actually set up preferences within the spree user model. Here, I show you how to &lt;code&gt;#class_eval&lt;/code&gt; it and add in the preferences:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Spree::User.class_eval do
  preference :first_name, :text
  preference :last_name, :text
end
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And that&amp;rsquo;s it! You&amp;rsquo;re done!&lt;/p&gt;
&lt;p&gt;Now its up to you to be able to setup the views/controllers properly, this blog post was just about setting up preferences for Spree 2.3.&lt;/p&gt;</description><link>http://blog.benmorgan.io/post/97340165086</link><guid>http://blog.benmorgan.io/post/97340165086</guid><pubDate>Fri, 12 Sep 2014 20:15:47 -0400</pubDate><category>spree</category><category>ruby on rails</category><category>ben morgan</category><category>ecommerce</category><category>preferences</category><category>spree 2.3.0</category></item><item><title>Passing Spree Objects from Rails to JavaScript</title><description>&lt;p&gt;I hate JavaScript. I really hate JavaScript. Everyone knows I hate JavaScript. I really hate it. Although I do love Dart. I freaking love Dart! I&amp;rsquo;d substitute &amp;ldquo;freak&amp;rdquo; with another word to go along with the way I usually talk, but considering this blog is public, I&amp;rsquo;ll be polite. JS sucks!&lt;/p&gt;
&lt;p&gt;But lately I&amp;rsquo;ve been working with AngularJS and having to do some frontend development on not just one, but &lt;em&gt;two&lt;/em&gt; spree applications at the same time. At first, I thought it was cool. I could collect the data through the Spree API, but somehow that didn&amp;rsquo;t seem plausible. the Object can be grabbed from the database via the rails and be passed off to the JavaScript via a rails controller and into an AngularJS controller. Hello headache!&lt;/p&gt;
&lt;p&gt;This works actually quite well when you&amp;rsquo;re on development, but it completely falls apart in production. You have to seperate every single JS file for Angular out from Sprockets and that just not fun. When this occurred, I began using &lt;a href="https://github.com/gazay/gon" target="_blank"&gt;Gon gem&lt;/a&gt;. Gon was actually quite efficient in sending over some information, but I couldn&amp;rsquo;t figure out how to sending over the large amounts of information that Spree comes with even at its bare minimums, pushing me to forfeit this attempt and move onto a new way: inline JS or data hooks. I did inline JS&amp;hellip;&lt;/p&gt;
&lt;p&gt;Then, on my second Spree project, I gave Gon another try. This time I succeeded and carried my knowledge back over to my original project, further developing my knowledge.&lt;/p&gt;
&lt;p&gt;First, lets get you Gon:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;# Gemfile
gem 'gon'
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now do a &lt;code&gt;bundle&lt;/code&gt; and add this line of code directly &lt;em&gt;before&lt;/em&gt; your &lt;code&gt;javascript_include_tag&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&amp;lt;!-- app/views/spree/_head.html.erb --&amp;gt;
&amp;lt;%= include_gon %&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;That&amp;rsquo;s it! You have gon installed!&lt;/p&gt;
&lt;p&gt;Now then, lets reopen the products controller and give Gon some data:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;# app/controllers/spree/products_controller_decorator.rb
Spree::ProductsController.class_eval do
  alias_method :super_show, :show

  def show
    super_show
    gon.product = @product.gon_object
  end
end
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now, Spree uses a &lt;code&gt;before_action&lt;/code&gt; to load up the &lt;code&gt;@product&lt;/code&gt; method for the &lt;code&gt;#show&lt;/code&gt; page. So we know we have access to &lt;code&gt;@product&lt;/code&gt;. The original &lt;code&gt;#show&lt;/code&gt; method has also been overwritten, so we&amp;rsquo;ve just aliased a method called &lt;code&gt;super_show&lt;/code&gt; to &lt;code&gt;show&lt;/code&gt; and continued with our work.&lt;/p&gt;
&lt;p&gt;Once done, when you reload the page you&amp;rsquo;ll get a method missing for the &lt;code&gt;#gon_object&lt;/code&gt; method. Lets fix that by reopening the product model class.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;# app/models/spree/products_decorator.rb
Spree::Product.class_eval do
  def gon_object
    {
      id: self.id,
      name: self.name,
      description: self.description,
      available_on: self.available_on,
      deleted_at: self.deleted_at
    }
  end
end
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now if you reload the browser, head on over to the product show page, you&amp;rsquo;ll see your product, but if you head on over to the console, the &lt;code&gt;gon&lt;/code&gt; object will be available to you. (One of the reasons I hate JS is how it defines &amp;ldquo;hashes/dictionaries&amp;rdquo; as &amp;ldquo;objects&amp;rdquo;. This I find straight up vexing. One small reason I &amp;lt;3 Dart.) Now lets write some JS.&lt;/p&gt;
&lt;p&gt;If you type &lt;code&gt;gon.product&lt;/code&gt; you&amp;rsquo;ll notice that you get that product hash right back out. I&amp;rsquo;m going to let you in on a secret, we didn&amp;rsquo;t have to write that &lt;code&gt;#gon_object&lt;/code&gt; method. We could have just said that &lt;code&gt;gon.product = @product&lt;/code&gt; and be done with it. Except this wouldn&amp;rsquo;t work because this &lt;em&gt;is&lt;/em&gt; the exact same hash that you get when you set it equal to &lt;code&gt;@product&lt;/code&gt;; there&amp;rsquo;s too little data.&lt;/p&gt;
&lt;p&gt;Try this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&amp;gt; gon.product.price
undefined
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And that is why we have our own custom &lt;code&gt;#gon_object&lt;/code&gt; method my friend. You see, the price of an object is stored not in the &lt;code&gt;spree_products&lt;/code&gt; table, but in the &lt;code&gt;spree_prices&lt;/code&gt; table. You can see an example here of the SQL doing on via the Rails console:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&amp;gt; Spree::Product.first.price
  Spree::Product Load (18.3ms)  SELECT  "spree_products".* FROM "spree_products"  WHERE "spree_products"."deleted_at" IS NULL  ORDER BY "spree_products"."id" ASC LIMIT 1
  Spree::Variant Load (3.4ms)  SELECT  "spree_variants".* FROM "spree_variants"  WHERE "spree_variants"."deleted_at" IS NULL AND "spree_variants"."product_id" = $1 AND "spree_variants"."is_master" = 't' LIMIT 1  [["product_id", 1]]
  Spree::Preference Load (0.6ms)  SELECT  "spree_preferences".* FROM "spree_preferences"  WHERE "spree_preferences"."key" = 'spree/app_configuration/currency' LIMIT 1
  Spree::Price Load (1.1ms)  SELECT  "spree_prices".* FROM "spree_prices"  WHERE "spree_prices"."variant_id" = $1 AND "spree_prices"."currency" = 'USD' LIMIT 1  [["variant_id", 1]]
 =&amp;gt; #&amp;lt;BigDecimal:7ff17a31f218,'0.1599E2',18(18)&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now then, lets edit that hash inside from the &lt;code&gt;#gon_object&lt;/code&gt; method inside of &lt;code&gt;Spree::Product&lt;/code&gt;. To get the price, we&amp;rsquo;ll just add a new key called &lt;code&gt;price&lt;/code&gt; and give it a pretty simple key:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;{
  ...
  price: self.price,
  ...
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now, if you go back into the browser console, you&amp;rsquo;ll notice that it gets written out as a string. (Why is everything saved as a freaking string in JS? Did you know that Dart is optionally typed?) To fixe this, we update the value to &lt;code&gt;self.price.to_f&lt;/code&gt; to make it a float number.&lt;/p&gt;
&lt;p&gt;Now that you have a way to get custom information from your model to your JS, lets give you a way to get those ActiveRecord relationships working.&lt;/p&gt;
&lt;p&gt;Since you&amp;rsquo;re on the product page, I&amp;rsquo;m going to assume you need to get at all the different variants for your product. Luckily in spree we can just do:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;{
  ...
  variants: self.variants,
  ...
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;That&amp;rsquo;s awesome! Now we have access to an array of variants! If you have to make variants customized (and I bet you will at some point to get anything useful out of it) then you&amp;rsquo;ll need to reopen the variants model and add a &lt;code&gt;#gon_object&lt;/code&gt; method inside of it as well.&lt;/p&gt;
&lt;p&gt;To do so, lets first update our variants value:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;{
  ...
  variants: self.variants.map(&amp;amp;:gon_object)
  ...
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now, lets reopen the Spree variants model and give it some awesomeness!&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Spree::Variant.class_eval do
  def gon_object
    {
      id: self.id,
      sku: self.sku,
      weight: self.weight.to_f,
      height: self.height.to_f,
      width: self.width.to_f,
      depth: self.depth.to_f,
      deleted_at: self.deleted_at,
      is_master: self.is_master,
      cost_price: self.cost_price.to_f,
      position: self.position,
      cost_currency: self.cost_currency,
      track_inventory: self.track_inventory,
      tax_category: self.tax_category
    }
  end
end
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This is awesome! Now we know exactly what what data we&amp;rsquo;re sending to the browser! If you look at the very last piece of data in the hash, you can see that we&amp;rsquo;re trying to get the &lt;code&gt;tax_category&lt;/code&gt; for the variant. This requires use to traverse from our initial variant model, over to the product, and out to the &lt;code&gt;spree_tax_categories&lt;/code&gt; table to get our row of data. I&amp;rsquo;m mentioning this for two reasons. One, its a really good reason for writing your own method for Gon and two, you need to think about n+1 problems. When this happens, please head over to where you originally called the &lt;code&gt;#gon_object&lt;/code&gt; and add an &lt;code&gt;#includes&lt;/code&gt; method for that table:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;# app/models/spree/product_decorator.rb
{
  ...
  variant: self.variants.includes(:variants).map(&amp;amp;:gon_object)
  ...
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And there we go, you&amp;rsquo;re all set. You now know how to pass data from Spree to JS large frontend applications. Woot!&lt;/p&gt;</description><link>http://blog.benmorgan.io/post/96761193711</link><guid>http://blog.benmorgan.io/post/96761193711</guid><pubDate>Sat, 06 Sep 2014 00:42:52 -0400</pubDate><category>spree</category><category>rails</category><category>javascript</category><category>angularjs</category><category>angular</category><category>ember</category><category>emberjs</category><category>backbone</category><category>backbonejs</category><category>gon</category><category>ruby</category><category>ruby on rails</category><category>objects</category><category>ecommerce</category></item><item><title>Background Jobs and Spree</title><description>&lt;p&gt;When working with Spree, you&amp;rsquo;ll need to at some point move some of the work onto a backgorund process. When this happens, you end up having a background smackdown on what to use. There&amp;rsquo;s delayed jobs, resque, and sidekiq. Not only that, but how optimized is Spree for background jobs?&lt;/p&gt;
&lt;p&gt;Well, to start I&amp;rsquo;ve worked on 3 spree applications in total. Yes, 3. One used delayed jobs, one used resque, and one used sidekiq.&lt;/p&gt;
&lt;p&gt;Now, delayed jobs is great if you don&amp;rsquo;t want to hook redis up. Personelly, I don&amp;rsquo;t think its the best option for Spree. Spree already goes a bit overkill on ActiveRecord and I feel like delayed jobs might just add more of a weight to it. Not only that, but both resque and sidekiq provide better services via redis, which is a lot faster. In other words, I don&amp;rsquo;t care if you don&amp;rsquo;t want to hook redis up to an app, you need to.&lt;/p&gt;
&lt;p&gt;When I began working with resque, it was just amazing. Setting up a worker class was also pretty easy and sending all the data over to redis was handled from the app&amp;rsquo;s end. When something went wrong, I went straight to the dashboard to figure it out. Moving to resque? Do it.&lt;/p&gt;
&lt;p&gt;But here&amp;rsquo;s the thing about resque: its for applications that are high in CPU, but from my experiences, Spree is more memory high than anything else. This is where sidekiq comes in. Not only that, but from working with Rails Dog, I&amp;rsquo;ve discovered that resque can have a bit of a &amp;ldquo;split brain&amp;rdquo;. Due to this, I think it would be best to switch from resque over to sidekiq if one is using resque. The best part: its an easy process.&lt;/p&gt;</description><link>http://blog.benmorgan.io/post/96104705321</link><guid>http://blog.benmorgan.io/post/96104705321</guid><pubDate>Fri, 29 Aug 2014 15:10:44 -0400</pubDate><category>spree</category><category>background jobs</category><category>rails</category><category>ruby</category><category>ruby on rails</category><category>delayed jobs</category><category>sidekiq</category><category>resque</category><category>redis</category></item><item><title>Getting Started with Spree, Wombat, and Ninefold</title><description>&lt;p&gt;&lt;span&gt;Imagine developing an application where you need to grab shipping data in real time, send products, inventory, and order information over at least ten different APIs including Amazon and eBay. When I first heard that I had to do this, there could only be one answer: &amp;ldquo;Challenge accepted&amp;rdquo;.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;If you&amp;rsquo;re reading this, then you probably know what Ninefold does and why you would use Spree, but let me introduce you to Wombat: the operating system for ecommerce applications.&lt;/p&gt;
&lt;p&gt;Now, Wombat has an enormous amount of documentation on how to use their app, but to be frank: they don&amp;rsquo;t have a lot yet when it comes to hooking Wombat up to Spree.&lt;/p&gt;
&lt;p&gt;In this blog post, we&amp;rsquo;re going to go from start to finish on building a Wombat application and then deploying it onto Ninefold.&lt;/p&gt;
&lt;h2&gt;Getting Started with Wombat&lt;/h2&gt;
&lt;p&gt;Lets first install spree with these commands:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;$ rails new wombat_app --database postgresql
$ cd wombat_app
$ spree install -A
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now that your store is set up, lets get Wombat installed. Simply add Wombat to your Gemfile:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;gem 'spree_wombat', github: 'spree/spree_wombat', branch: '2-3-stable'
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And when you&amp;rsquo;re ready:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;$ bundle
$ bundle exec rails g spree_wombat:install
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Once that is finished, head over to &lt;a href="http://wombat.co" target="_blank"&gt;Wombat&lt;/a&gt; and sign up for a two week trial. When you&amp;rsquo;re set up, update &lt;code&gt;config/initializers/wombat.rb&lt;/code&gt; to include your connection token and ID.&lt;/p&gt;
&lt;h2&gt;Wombat Configuration&lt;/h2&gt;
&lt;p&gt;Inside of the Wombat configuration, you&amp;rsquo;ll see that there&amp;rsquo;s a &lt;code&gt;#push_objects&lt;/code&gt; method. In here, you will have an array of strings that Wombat can use to identify which object you want to send up to Wombat.&lt;/p&gt;
&lt;p&gt;Inside of the &lt;code&gt;#payload_builder&lt;/code&gt; this is where you&amp;rsquo;ll add the JSON to get pushed up to Wombat. The &lt;code&gt;:root&lt;/code&gt; is used to tell Wombat exactly what type of JSON you&amp;rsquo;re giving it. You want this because in Wombat, you call your users &amp;ldquo;customers&amp;rdquo;, therefore you would need a way to specify how Wombat should interpret the data vs your application (this is how Wombat is made universal and app-agnostic). Now, to grab the JSON that Wombat will need to send up to cloud, you use a serializer. Wombat comes with &lt;a href="https://github.com/spree/spree_wombat/tree/master/app/serializers/spree/wombat" target="_blank"&gt;some serializers upfront&lt;/a&gt; (except a user serializer, but I&amp;rsquo;ll show you how to make that further on).&lt;/p&gt;
&lt;p&gt;Finally, we have &lt;code&gt;#push_url&lt;/code&gt; which will push the data to wombat. Leave it to its default unless you customize your Wombat profile; you&amp;rsquo;ll know if you need to change it.&lt;/p&gt;
&lt;h2&gt;Pushing Data Manually to Wombat&lt;/h2&gt;
&lt;p&gt;If you set up Spree and Wombat correctly, then you should be able to send two Spree example orders up to Wombat. To do this, lets enter the rails console (with &lt;code&gt;rails c&lt;/code&gt;):&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&amp;gt; Spree::Wombat::Client.push_batches("Spree::Order")
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;If you check out your Wombat page, you should see that those orders have been pushed up. If you want to send &lt;em&gt;all&lt;/em&gt; of the objects that you have defined in Wombat (and there are times that you will want to do this), then you would use Wombat&amp;rsquo;s built in rake task:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;$ bundle exec rake wombat:push_it
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;If you check out Wombat, you should see all of your products up there as well.&lt;/p&gt;
&lt;h2&gt;Adding a Wombat Serializer&lt;/h2&gt;
&lt;p&gt;This is all fine and dandy, but you happen to have some shipments you want up on Wombat as well. Thankfully, Wombat already has this &lt;a href="https://github.com/spree/spree_wombat/blob/master/app/serializers/spree/wombat/shipment_serializer.rb" target="_blank"&gt;shipment serializer&lt;/a&gt; predone for you! Lets set this up within our application.&lt;/p&gt;
&lt;p&gt;Set your &lt;code&gt;#push_objects&lt;/code&gt; to include the &lt;code&gt;"Spree::Shipment"&lt;/code&gt; model:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;config.push_objects = ["Spree::Order", "Spree::Product", "Spree::Shipment"]
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now, inside of your &lt;code&gt;#payload_builder&lt;/code&gt;, you&amp;rsquo;ll want to make sure you add it as a key (&lt;code&gt;"Spree::Shipment"&lt;/code&gt;) with a Hash as a value (&lt;code&gt;{ serializer: "Spree::Wombat::ShipmentSerializer", root: "shipments" }&lt;/code&gt;). This should give you:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;config.payload_builder = {
  "Spree::Order" =&amp;gt; { serializer: "Spree::Wombat::OrderSerializer", root: "orders" },
  "Spree::Product" =&amp;gt; { serializer: "Spree::Wombat::ProductSerializer", root: "products" },
  "Spree::Shipment" =&amp;gt; { serializer: "Spree::Wombat::ShipmentSerializer", root: "shipments" }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now, if you perform &lt;code&gt;Spree::Wombat::Client.push_batches("Spree::Shipment")&lt;/code&gt; you should be able to see it in Wombat.&lt;/p&gt;
&lt;h2&gt;Adding a Custom Serializer&lt;/h2&gt;
&lt;p&gt;You now have three objects hitting Wombat. Wombat lists four objects it will take by defualt. Let&amp;rsquo;s give it the final one: customers!&lt;/p&gt;
&lt;p&gt;To begin, we will generate the serializer using Wombat&amp;rsquo;s serializer generator:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;bundle exec rails g spree_wombat:serializer Spree::User UserSerializer
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Within the &lt;code&gt;app/serializers/user_serializer.rb&lt;/code&gt; this is the code that I use:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;require 'active_model/serializer'

class UserSerializer &amp;lt; ActiveModel::Serializer
  attributes :id, :firstname, :lastname, :email, :shipping_address, :billing_address

  def id
    object.id
  end

  def firstname
    object.try :first_name
  end

  def lastname
    object.try :last_name
  end

  def email
    object.email
  end

  def shipping_address
    address_hash object.shipping_address
  end

  def billing_address
    address_hash object.billing_address
  end

  private

  def address_hash(address)
    {
      address1: address.address1,
      address2: address.address2,
      zipcode: address.zipcode,
      city: address.city,
      state: address.state.name,
      country: address.country.name,
      phone: address.phone
    }
  end
end
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Your &lt;code&gt;#push_objects&lt;/code&gt; should now look like:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;config.push_objects = ["Spree::Order", "Spree::Product", "Spree::Shipment", "Spree::User"]
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And your &lt;code&gt;#payload_builder&lt;/code&gt; should be:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;config.payload_builder = {
  "Spree::Order" =&amp;gt; { serializer: "Spree::Wombat::OrderSerializer", root: "orders" },
  "Spree::Product" =&amp;gt; { serializer: "Spree::Wombat::ProductSerializer", root: "products" },
  "Spree::Shipment" =&amp;gt; { serializer: "Spree::Wombat::ShipmentSerializer", root: "shipments" },
  "Spree::User" =&amp;gt; { serializer: "UserSerializer", root: "customers" }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Using After Commits with Wombat&lt;/h2&gt;
&lt;p&gt;Now that this is all done, you&amp;rsquo;re probably tired of doing it manually. Using decorators, you can add some &lt;code&gt;after_commit&lt;/code&gt;s to push the model&amp;rsquo;s data up to Wombat when an ActiveRecord transaction has finished. Here&amp;rsquo;s an example using the &lt;code&gt;Spree::Shipment&lt;/code&gt; model:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;# app/models/spree/shipment_decorator.rb
Spree::Shipment.class_eval do
  after_commit :wombat_push_spree_shipments, on: [:create, :update]

  private

  def wombat_push_spree_shipments
    Spree::Wombat::Client.push_batches("Spree::Shipment")
  end
end
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now, if you create a new shipment (and follow this pattern for your other three models) then you should be able to get your data up to wombat in realtime.&lt;/p&gt;
&lt;h2&gt;Using Workers with Wombat&lt;/h2&gt;
&lt;p&gt;There&amp;rsquo;s an issue with this though. What if the page takes two seconds to load and eight seconds to get updated on Wombat? That means that you&amp;rsquo;ll have eight seconds of blocking code and the amount of time on the server to render the next page for the user would be ten seconds. To get around this, we&amp;rsquo;re going to set up a Wombat worker and get it done using Resque.&lt;/p&gt;
&lt;p&gt;To begin, we&amp;rsquo;re going to need to install Redis. To do so, follow Redis Rails installation instructions. When finished, add Resque to your Gemfile:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;gem 'resque', '~&amp;gt; 1.25', require: 'resque/server'
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;After bundling, start up these three servers:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;web: rails s
redis: redis-server redis.conf
worker: bundle exec rake resque:work QUEUE=* TERM_CHILD=1
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;You should be good to go. Now, inside fo your &lt;code&gt;Spree::Shipment&lt;/code&gt; model, update it to:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Spree::Shipment.class_eval do
  after_commit :wombat_push_spree_shipments, on: [:create, :update]

  private

  def wombat_push_spree_shipments
    Resque.enqueue(WombatWorker, "Spree::Shipment")
  end
end
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The only ine that we&amp;rsquo;ve changed is line 7 where we state that we&amp;rsquo;re going to be using Resque. The first argument is &lt;code&gt;WombatWorker&lt;/code&gt; which is the class of the worker that will handle anything and everything Wombat. First, in your &lt;code&gt;application.rb&lt;/code&gt; add the &lt;code&gt;workers&lt;/code&gt; directory to your load path:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;# Load application's workers
Dir.glob(File.join(File.dirname(__FILE__), "../app/workers/*_worker.rb")) do |c|
  Rails.configuration.cache_classes ? require(c) : load(c)
end
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;When finished, restart your web server and make a new file called &lt;code&gt;app/workers/wombat_worker.rb&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;# app/workers/wombat_worker.rb
class WombatWorker
  @queue = :wombat_worker_queue

  def self.perform(wombat_payload)
    Spree::Wombat::Client.push_batches(wombat_payload)
  end
end
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Using &lt;code&gt;@queue&lt;/code&gt; we name the queue using a symbol and then use &lt;code&gt;#perform&lt;/code&gt; to execute the worker code. Here, &lt;code&gt;wombat_payload&lt;/code&gt; will be whatever our second argument is in the &lt;code&gt;Resque.enqueue&lt;/code&gt; method that we added within the spree shipment decorator.&lt;/p&gt;
&lt;h2&gt;Deploying to Ninefold&lt;/h2&gt;
&lt;p&gt;Lets get this app onto Ninefold. First, we&amp;rsquo;ll need a Procfile:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;# Procfile
redis: redis-server redis.conf
worker: bundle exec rake resque:work QUEUE=* TERM_CHILD=1
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Push up all your code to Github and then head over to &lt;a href="http://ninefold.com" target="_blank"&gt;Ninefold&lt;/a&gt; to sign up as a new user.&lt;/p&gt;
&lt;p&gt;When done, sign in and create a new application. Select where you&amp;rsquo;re storing your code (such as Github) and then you should be on step 2. If not, you&amp;rsquo;ll be asked to sign into Github through Ninefold. Now, you specify the account, repo, and which branch or release that you would like to deploy to. It will then ensure that you are using PostgreSQL, that you do not have &lt;code&gt;rails_12factor&lt;/code&gt; gem, and that your application is a valid Rails app.&lt;/p&gt;
&lt;p&gt;On step 3, you get to choose your architecture. You&amp;rsquo;re going to need a web server, so go ahead and make sure you&amp;rsquo;re using the 2GB - 1vCPU in whichever region is closest to you. Make sure you have a dedicated PG database server for your app (makes it easy to scale). Yes, you would like a background worker for your app and you will want it dedicated. Also make sure that this is a 1GB - 1vCPU server. Finally, push the &amp;ldquo;Next&amp;rdquo; button and you should be on Step 4 deployin gyour application&lt;/p&gt;
&lt;h2&gt;Wrapping Up&lt;/h2&gt;
&lt;p&gt;Throughout this blog post, you have discovered how to install Spree and Wombat, send data to Wombat, set up serializers, set up a &lt;code&gt;WombatWorker&lt;/code&gt;, and finally deploy it onto production using Ninefold. I hope this blog post was informative and useful. Have fun!&lt;/p&gt;</description><link>http://blog.benmorgan.io/post/95144946546</link><guid>http://blog.benmorgan.io/post/95144946546</guid><pubDate>Mon, 18 Aug 2014 20:58:00 -0400</pubDate><category>wombat</category><category>ninefold</category><category>spree</category><category>ruby</category><category>ruby on rails</category><category>rails</category><category>web development</category><category>resque</category><category>redis</category><category>workers</category></item><item><title>Zeus with Foreman</title><description>&lt;p&gt;Quite often, I find that Foreman and Zeus don&amp;rsquo;t always go hand in hand, so in this quick write up, I&amp;rsquo;m going to show you how to get the power of Zeus inside of the great Foreman.&lt;/p&gt;
&lt;p&gt;To start, lets assume that this is what our Profile looks like:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;web: bundle exec thin start -p $PORT
redis: redis-server redis.conf
worker: bundle exec rake resque:work QUEUE=* TERM_CHILD=1
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;That&amp;rsquo;s great, except if we want to run zeus with it, we have to have two tabs open. One tab runs &lt;code&gt;zeus start&lt;/code&gt; and the other tab run the Procfile as:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;web: zeus s
redis: redis-server redis.conf
worker: bundle exec rake resque:work QUEUE=* TERM_CHILD=1
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;OK, that&amp;rsquo;s kinda works, but now we have two tabs. Let&amp;rsquo;s change that:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;zeus: zeus start
web: zeus s
redis: redis-server redis.conf
worker: bundle exec rake resque:work QUEUE=* TERM_CHILD=1
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This breaks one in a while since Foreman will start each process randomly giving us the &lt;code&gt;Can't connect to master. Run zeus start first.&lt;/code&gt; error.&lt;/p&gt;
&lt;p&gt;To get past this, we will update the Procfile to:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;zeus: zeus start
web: sleep 2 &amp;amp;&amp;amp; zeus s
redis: redis-server redis.conf
worker: bundle exec rake resque:work QUEUE=* TERM_CHILD=1
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now we can have &lt;code&gt;web&lt;/code&gt; sleep for 2 seconds, giving it enough time to detect &lt;code&gt;zeus start&lt;/code&gt; and therefore stalling until it receives the green light from Zeus.&lt;/p&gt;
&lt;p&gt;We&amp;rsquo;re not done yet. You may notice that the output is not so pretty anymore. Instead, try this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;zeus: zeus start &amp;amp;&amp;gt; /dev/null
web: sleep 2 &amp;amp;&amp;amp; zeus s
redis: redis-server redis.conf
worker: bundle exec rake resque:work QUEUE=* TERM_CHILD=1
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This is great, but now we don&amp;rsquo;t know when Zeus is starting. To fix this we&amp;rsquo;ll add a simple echo:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;zeus: echo "Starting Zeus..." &amp;amp;&amp;amp; zeus start &amp;amp;&amp;gt; /dev/null
web: sleep 2 &amp;amp;&amp;amp; zeus s
redis: redis-server redis.conf
worker: bundle exec rake resque:work QUEUE=* TERM_CHILD=1
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And there we go, you now know how to get Zeus and Foreman running together. Have fun!&lt;/p&gt;</description><link>http://blog.benmorgan.io/post/93909470451</link><guid>http://blog.benmorgan.io/post/93909470451</guid><pubDate>Tue, 05 Aug 2014 18:02:42 -0400</pubDate><category>zeus</category><category>foreman</category><category>ben morgan</category><category>processes</category><category>rails</category><category>ruby</category><category>ruby on rails</category><category>development workflow</category></item><item><title>We are unable to calculate shipping rates for the selected items.</title><description>&lt;p&gt;In Spree, I run into this error a LOT and it always takes some time to debug, so here, I am not only going to solve it and make a detailed listing of what the possible issues are, but make sure that I don&amp;rsquo;t spend another two hours going through this head ache.&lt;/p&gt;
&lt;p&gt;What happens is that when you are using Spree, you will hit the checkout page and you will submit your address information. On submission you ge this infamous error.&lt;/p&gt;
&lt;p&gt;This error is caused because you have either made a product with no shipping information (which is easy to solve) or your tax information is not correct&amp;hellip;&lt;/p&gt;
&lt;p&gt;to solve the shipping method error, just slip over to the admin product edit page and see if the product you&amp;rsquo;re trying to but has a shipping method. It usually does and this unlikely the error. Anywho, just select Default in the drop down if you&amp;rsquo;re on a brand new store.&lt;/p&gt;
&lt;p&gt;If, however, this is not the solution (and it probably isn&amp;rsquo;t), then you need to do some taxes. To start, lets talk about zones. Zones in spree define exactly in what areas of the world some tax information applies to. This a great junction to introduct the problem because (a) you might not have a zone set up for your default tax or (b) the problem now lies in either the countries/states or the tax information.&lt;/p&gt;
&lt;p&gt;In the right side bar to the configuration, do you see a &amp;ldquo;States&amp;rdquo; button? If you don&amp;rsquo;t you might want to load up this data into your app:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/spree/spree/blob/master/core/db/default/spree/countries.rb" target="_blank"&gt;The Countries.&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/spree/spree/blob/master/core/db/default/spree/states.rb" target="_blank"&gt;The States.&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/spree/spree/blob/master/core/db/default/spree/zones.rb" target="_blank"&gt;The Zones.&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;And since Spree (as of 2.3.1) does not contain the Canadian states:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;canada = Spree::Country.find_by_name('Canada')
Spree::State.create!([
 { "name" =&amp;gt; "Yukon", "abbr" =&amp;gt; "YT", country: canada },
 { "name" =&amp;gt; "Nunavut", "abbr" =&amp;gt; "NU", country: canada },
 { "name" =&amp;gt; "British Columbia", "abbr" =&amp;gt; "BC", country: canada },
 { "name" =&amp;gt; "Alberta", "abbr" =&amp;gt; "AB", country: canada },
 { "name" =&amp;gt; "Saskatchewan", "abbr" =&amp;gt; "SK", country: canada },
 { "name" =&amp;gt; "Manitoba", "abbr" =&amp;gt; "MB", country: canada },
 { "name" =&amp;gt; "Ontario", "abbr" =&amp;gt; "ON", country: canada },
 { "name" =&amp;gt; "Quebec", "abbr" =&amp;gt; "QC", country: canada },
 { "name" =&amp;gt; "New Brunswick", "abbr" =&amp;gt; "NB", country: canada },
 { "name" =&amp;gt; "Newfoundland and Labrador", "abbr" =&amp;gt; "NL", country: canada },
 { "name" =&amp;gt; "Nova Scotia", "abbr" =&amp;gt; "NS", country: canada },
 { "name" =&amp;gt; "Prince Edward Island", "abbr" =&amp;gt; "PE", country: canada },
 { "name" =&amp;gt; "Northwest Territories", "abbr" =&amp;gt; "NT", country: canada }
])
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And now your app works for the geography. Lets hook up the tax information.&lt;/p&gt;
&lt;p&gt;There are currently three settings for taxes: Tax Categories, Tax Rates, and Tax Settings.&lt;/p&gt;
&lt;p&gt;We&amp;rsquo;ll go ahead and create a tax category and tax rate for clothing using Spree Sample&amp;rsquo;s data.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Spree::TaxCategory.create!(:name =&amp;gt; "Clothing")
north_america = Spree::Zone.find_by_name!("North America")
clothing = Spree::TaxCategory.find_by_name!("Clothing")
tax_rate = Spree::TaxRate.create(
  :name =&amp;gt; "North America",
  :zone =&amp;gt; north_america,
  :amount =&amp;gt; 0.05,
  :tax_category =&amp;gt; clothing)
tax_rate.calculator = Spree::Calculator::DefaultTax.create!
tax_rate.save!
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now, if you head into the admin section and set clothing as the default and the North America zone as your default you should be good to go from the tax/geo section of this error.&lt;/p&gt;
&lt;p&gt;But, wait, remember that this was also being caused because of the shipping information?&lt;/p&gt;
&lt;p&gt;Well, you can solve this by adding in shipping information, or rather, shipping methods:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;begin
  north_america = Spree::Zone.find_by_name!("North America")
rescue ActiveRecord::RecordNotFound
  puts "Couldn't find 'North America' zone. Did you run `rake db:seed` first?"
  puts "That task will set up the countries, states and zones required for Spree."
  exit
end

europe_vat = Spree::Zone.find_by_name!("EU_VAT")
shipping_category = Spree::ShippingCategory.find_or_create_by!(name: 'Default')

Spree::ShippingMethod.create!([
  {
    :name =&amp;gt; "UPS Ground (USD)",
    :zones =&amp;gt; [north_america],
    :calculator =&amp;gt; Spree::Calculator::Shipping::FlatRate.create!,
    :shipping_categories =&amp;gt; [shipping_category]
  },
  {
    :name =&amp;gt; "UPS Two Day (USD)",
    :zones =&amp;gt; [north_america],
    :calculator =&amp;gt; Spree::Calculator::Shipping::FlatRate.create!,
    :shipping_categories =&amp;gt; [shipping_category]
  },
  {
    :name =&amp;gt; "UPS One Day (USD)",
    :zones =&amp;gt; [north_america],
    :calculator =&amp;gt; Spree::Calculator::Shipping::FlatRate.create!,
    :shipping_categories =&amp;gt; [shipping_category]
  },
  {
    :name =&amp;gt; "UPS Ground (EU)",
    :zones =&amp;gt; [europe_vat],
    :calculator =&amp;gt; Spree::Calculator::Shipping::FlatRate.create!,
    :shipping_categories =&amp;gt; [shipping_category]
  },
  {
    :name =&amp;gt; "UPS Ground (EUR)",
    :zones =&amp;gt; [europe_vat],
    :calculator =&amp;gt; Spree::Calculator::Shipping::FlatRate.create!,
    :shipping_categories =&amp;gt; [shipping_category]
  }
])

{
  "UPS Ground (USD)" =&amp;gt; [5, "USD"],
  "UPS Ground (EU)" =&amp;gt; [5, "USD"],
  "UPS One Day (USD)" =&amp;gt; [15, "USD"],
  "UPS Two Day (USD)" =&amp;gt; [10, "USD"],
  "UPS Ground (EUR)" =&amp;gt; [8, "EUR"]
}.each do |shipping_method_name, (price, currency)|
  shipping_method = Spree::ShippingMethod.find_by_name!(shipping_method_name)
  shipping_method.calculator.preferences = {
    amount: price,
    currency: currency
  }
  shipping_method.calculator.save!
  shipping_method.save!
end
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Hope that works for you! It works for me. Have at it.&lt;/p&gt;</description><link>http://blog.benmorgan.io/post/92211936811</link><guid>http://blog.benmorgan.io/post/92211936811</guid><pubDate>Sat, 19 Jul 2014 00:59:00 -0400</pubDate><category>spree</category><category>ben morgan</category><category>ruby on rails</category><category>ruby</category><category>web development</category><category>programming</category></item><item><title>Getting Started with Spree</title><description>&lt;p&gt;&lt;a href="http://spreecommerce.com/" target="_blank"&gt;Spree&lt;/a&gt; is an ecommerce framework for &lt;a href="http://guides.rubyonrails.org/" target="_blank"&gt;Ruby on Rails&lt;/a&gt; that is currently at version 2.2.2. I often find that individuals come to spree when Magento or Shopify just can&amp;rsquo;t serve their needs anymore and they need an even more custom solution.&lt;/p&gt;
&lt;p&gt;To get started, we first need to install spree:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;$ gem install spree
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;OK, that was fun, now let&amp;rsquo;s go ahead and make a new rails project:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;$ rails _4.0.5_ new spree_app
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now that you have that done, try this out:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;$ spree install spree_app
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Or, if you&amp;rsquo;ve already navigated into &lt;code&gt;spree_app&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;$ spree install .
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;You will get a number of questions:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Would you like to install the default gateways? (Recommended) (yes/no) [yes]
Would you like to install the default authentication system? (yes/no) [yes]
Would you like to run the migrations? (yes/no) [yes]
Would you like to load the seed data? (yes/no) [yes]
Would you like to load the sample data? (yes/no) [yes]
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Right now, please answer yes (the default) to all of them. When starting a new spree project, I often do &lt;code&gt;spree install . -A&lt;/code&gt; which auto-accepts all parameters.&lt;/p&gt;
&lt;p&gt;Now, as its installing, it will stop and ask you to create an Admin user:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Create the admin user (press enter for defaults).
Email [spree@example.com]:
Password [spree123]:
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Just push the default options so that we can get going.&lt;/p&gt;
&lt;p&gt;Throughout the installation, you might have noticed this warning:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;[WARNING] You are not setting Devise.secret_key within your application!
You must set this in config/initializers/devise.rb. Here's an example:

Devise.secret_key = "a0c5e56c8764a93b03fce02083f4aed18aef63ef4d7be33f351accb002d4e2187ac6ba4a78090c341281f51a6abebd4fe499"
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now I&amp;rsquo;m going to tell you how to solve this. If you open up your &lt;code&gt;Gemfile&lt;/code&gt; it should look like this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;source 'https://rubygems.org'

gem 'rails', '4.0.5'
gem 'sqlite3'

gem 'sass-rails', '~&amp;gt; 4.0.2'
gem 'uglifier', '&amp;gt;= 1.3.0'
gem 'coffee-rails', '~&amp;gt; 4.0.0'

gem 'jquery-rails'
gem 'turbolinks'
gem 'jbuilder', '~&amp;gt; 1.2'

group :doc do
  gem 'sdoc', require: false
end

gem 'spree', '2.2.2'
gem 'spree_gateway', github: 'spree/spree_gateway', branch: '2-2-stable'
gem 'spree_auth_devise', github: 'spree/spree_auth_devise', branch: '2-2-stable'
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Notice at the bottom there were 3 gems that got installed. &lt;code&gt;spree&lt;/code&gt; is the main project and is definately what you wanted to install. There&amp;rsquo;s also two more: &lt;code&gt;spree_gateway&lt;/code&gt; and &lt;code&gt;spree_auth_devise&lt;/code&gt;. &lt;code&gt;spree_gateway&lt;/code&gt; basically handles active merchant, stripe, checks, stuff that allows you to receive money. &lt;code&gt;spree_auth_devise&lt;/code&gt; is used for authenticating users. Its different from devise in that it requires you to be running &lt;code&gt;devise&lt;/code&gt;; since bundler detects that you don&amp;rsquo;t have it in your &lt;code&gt;Gemfile&lt;/code&gt;, it does it for you - the magic of Bundler.&lt;/p&gt;
&lt;p&gt;Because &lt;code&gt;spree_auth_devise&lt;/code&gt; is its own gem, it actually never got installed fully when you ran &lt;code&gt;spree install&lt;/code&gt;. Therefore, we have to do another installation for &lt;code&gt;spree_auth_devise&lt;/code&gt;. Here&amp;rsquo;s how you install &lt;code&gt;spree_auth_devise&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;$ bundle exec rails g spree:auth:install
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;you will see the error pop up one more time and then directly after that you get:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;create  config/initializers/devise.rb
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And there we go, its gone. Alternatively, you could have also created the initializer yourself and copy and pasted the devise secret key. To generate secret keys, you can use &lt;code&gt;rake secret&lt;/code&gt; like so:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;$ rake secret
9ba50700679fc17712ce1a1538bb9dd05c31038e12d1155cb8d437a9dd69a0a2fc8b7f9425f254c77d5bfa0587c9e50df0931f3803d947eb5fe13c7d1b6cec00
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And there you go, now lets start the application:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;$ rails s
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;IF you head over to &lt;code&gt;localhost:3000&lt;/code&gt; you will see the spree skeleton. Awesome! But, you probably don&amp;rsquo;t like that design, so lets get bootstrap in there! In your &lt;code&gt;Gemfile&lt;/code&gt;, add:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;gem 'spree_bootstrap_frontend', github: '200Creative/spree_bootstrap_frontend', branch: '2-2-stable'
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now, &lt;code&gt;bundle&lt;/code&gt; and then run:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;$ rails generate spree_bootstrap_frontend:install
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;It should now ask you if you would like to overwrite one of your assets. Answer &lt;code&gt;Y&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;If everything is working for you right now, just go and type in &lt;code&gt;rails s&lt;/code&gt; and watch the design completely change for the better.&lt;/p&gt;
&lt;p&gt;You can now change the theme of you spree application with ease!&lt;/p&gt;</description><link>http://blog.benmorgan.io/post/89825694756</link><guid>http://blog.benmorgan.io/post/89825694756</guid><pubDate>Tue, 24 Jun 2014 23:43:04 -0400</pubDate><category>spree</category><category>ben morgan</category><category>ruby on rails</category><category>ecommerce</category><category>bootstrap</category><category>getting started</category></item></channel></rss>
