Spree Commerce, custom admin routes – Attempt 2

Last post I've added a module attribute for the spree backend for supplying the configuration data.

I think it's much cleaner to use Spree's build in configuration system.
The admin path now is a normal Spree setting. You can supply it in the Spree initializer:

Spree.config do |config|
  config.admin_path = "/super-secret-name"
end

The code changes required in Spree for this solution only is 3 lines!
Add the admin_path preference to this file core/app/models/spree/app_configuration.rb

module Spree
  class AppConfiguration < Preferences::Configuration
    #...
    preference :admin_path, :string, default: "/admin"
    #...
  end
end

And alter the backend/config/routes.rb, to include a path definition in the top namespace and change the '/admin' path route of the last line.

Spree::Core::Engine.add_routes do
  namespace :admin, path: Spree::Config.admin_path do
 
    #.. everything remains the same, except this last line:
    get Spree::Config.admin_path, to: 'admin/root#index', as: :admin
 
  end
end

That's all...
Sending in a PullRequest now :)

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;
}

Affinity Designer

Finally there's a descent alternative to Illustrator.
I bought Affinity Designer and I really like it!!

dragon-david-sketch

dragin-david-line-drawing

dragon-david-shades-and-lines

dragon-david-complete

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