Rails : Spree in production [Deface stuffs]

Spree In production

You need to take these things into consideration while deploying your spree app to production. Like, the login button/link might not appear even when your app is up and running. Or may appear twice.

Deface supports precompiling where all overrides are loaded and applied to the original views and the resulting templates are then saved to your application’s app/compiled_views directory. To precompile run:

 $ bundle exec rake deface:precompile

It’s important to disable Deface once precompiling is used to prevent overrides getting applied twice. To disable add the following line to your application’s production.rb file:

config.deface.enabled = false

Additionally,

After every deploy to production you will face this issue and you manually have to recompile the overrides. Its so cumbersome and annoying to do it every time. So I would prefer to make a Capistrano recipe and inject it to the deployment workflow.

There are two ways to execute the recipe

  • You can re-compile every time
  • You can once recompile in `shared` folder and symlink every time. You can invoke the task if there is change in the overrides.

 

namespace :deface do
  task :precompile do
    SSHKit.config.command_map[:rake] = "./bin/rake"

    on roles(:web) do
      set :current_path, "#{fetch(:deploy_to)}/current/"
      within fetch(:current_path) do
        with rails_env: fetch(:rails_env) do
          execute :rake, 'deface:precompile'
        end
      end
    end
  end
end

# in deploy.rb
before 'deploy:restart', 'deface:precompile'

NOTE: You can also use precompiling in development mode. Make sure you restart the application server every time you precompile the overrides.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s