Spree Commerce, custom admin routes

At the moment Spree uses a hardcoded /admin path for accessing the backend.
I really, really would like if this was configurable.

The solution could be pretty simple:

file: /lib/spree_backend.rb (spree/backend/lib/spree_backend.rb)

  module Spree::Backend
    mattr_accessor :route_admin_path
    @@route_admin_path = "/admin"

    def self.config
      yield self
    end  
  end

Next in spree /config/routes.rb (spree/backend/config/routes.rb)

Spree::Core::Engine.add_routes do
  namespace :admin, path: Spree::Backend.route_admin_path do

    #.. everything remains the same, except this last line:
    get Spree::Backend.route_admin_path, to: 'admin/root#index', as: :admin

  end
end

And ready, you can now configure your admin path, via an initializer of your application

Spree::Backend.config do |config|
  config.route_admin_path = '/super-secret-name'
end

I know it's security by obscurity, but it makes building automated attacks much more difficult.
Which is very important if there are known security issues.

Warning: Plugins are not converted and use the default /admin path. But these plugins can be changed easily by adding the path: Spree::Backend.route_admin_path option!

Please tell my what do you think of this solution?!?

Vertical align in 3 css lines

Nice trick from:
http://zerosixthree.se/vertical-align-anything-with-just-3-lines-of-css/

/* not required half pixel fix */
.parent-element {
  -webkit-transform-style: preserve-3d;
  -moz-transform-style: preserve-3d;
  transform-style: preserve-3d;
}

/* this is all to vertical align */
.element {
  position: relative;
  top: 50%;
  transform: translateY(-50%);
}

Unfortunately the solution above doesn't seem to work correctly in Safari

This one seems to work better
https://stackoverflow.com/questions/7273338/how-to-vertically-align-an-image-inside-div/18869078#18869078

<div class="frame">
  <img src=foo"/>
</div>
.frame {  
    height: 160px; /*can be anything*/
    width: 160px; /*can be anything*/
    position: relative;
}
img {  
    max-height: 100%;  
    max-width: 100%; 
    width: auto;
    height: auto;
    position: absolute;  
    top: 0;  
    bottom: 0;  
    left: 0;  
    right: 0;  
    margin: auto;
}

Rails Email Preview

Just a short post for myself to remember the ActionMailer Preview functionality.

test/mailers/previews/mailer_preview.rb

class MailerPreview < ActionMailer::Preview
  def mailer_method_name
    TeamPersonMailer.mailer_method_name( email_method_argument ) 
  end
end

And view your preview emails at: http://localhost:3000/rails/mailers

Opinion: Magento Hell !

Overriding a class in Magento. The nice way to do it is to define your own module and override the class. (2 xml files, 1 source file. distributed over the source tree :S )

<?xml version="1.0"?>
<config>
	<modules>
   		<Company_Shipping>
			<active>true</active>
			<codepool>local</codepool>
  		</Company_Shipping>
	</modules>
 </config>

This didn't work. No errors, no message just didn't activate my module.
This did work. Find the differences:

<?xml version="1.0"?>
<config>
	<modules>
   		<Company_Shipping>
			<active>true</active>
			<codePool>local</codePool>
  		</Company_Shipping>
	</modules>
 </config>

(Check the word codepool instead of codePool)

Every time I'm working with Magento I get these kind of problems and issues. It takes to much time to make simple changes. Way to much configuration. No descent error messages. Files littered across multiple folders.

:S

Makes me glad I can work with Spree (and Rails) most of the time. With nice convention based overrides. Gem support. Nice deployment. Git friendly etc. ;)

RVM / Ruby Certificate Issues on FreeBSD

Today I was trying to deploy my updated rails application via capistrano
Suddenly I've got the following message

ERROR:  While executing gem ... (Gem::RemoteFetcher::FetchError)
    SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed

Trying to update the gem system manually had the same problem:

[root@w1 ~]# gem update --system
ERROR:  While executing gem ... (Gem::RemoteFetcher::FetchError)
    SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed (https://api.rubygems.org/specs.4.8.gz)

Setting the environment variable 'SSL_CERT_FILE' to the location of the root-certificates from the ports collect ion resolved the issue:

[root@w1 ~]# SSL_CERT_FILE=/usr/local/etc/ssl/cert.pem  gem update --system
Updating rubygems-update
Fetching: rubygems-update-2.4.5.gem (100%)
Successfully installed rubygems-update-2.4.5

Now I've reinstalled the port security/ca_root_nss and enabled the ETCSYMLINK option. This resolved my issue. Now my system uses the latest root-certificates. (*duh*)

Just a note, had another rails project, that didn't work out of the box. Fixed this by adjusting the deploy.rb script. I've added the following:

set :default_env, { 
  SSL_CERT_FILE: '/etc/ssl/cert.pem'
}