How to disable Bullet in ActionMailer previews - ruby-on-rails

I would like to disable the Bullet gem when previewing emails using ActionMailer::Preview. In the Bullet readme, there is an instructon on how do to this for a controller, but how do I apply this to my ActionMailer previews? In my app, the previews are configured to appear at
config.action_mailer.preview_path = "#{Rails.root}/mailers_previews/"

As a workaround, I have added the following to my config/environments/development.rb
config.after_initialize do
Bullet.enable = false
pp 'Bullet Disabled' unless Bullet.enable?
... other settings ...
end
The warning is so I do not forget to set Bullet.enable = true when I have finished working on my action mailer previews. You need to restart the server to enable/disable Bullet.

Related

Bootstrap-Sass: Glyphicons showing as rectangles on production

See the top right "admin" icon on http://base.sirius.uberspace.de/en.
When setting
config.assets.compile = true
they're showing correctly, but I guess that's not the perfect solution, is it?
Setting
config.assets.precompile += %w( '.woff', '.eot', '.svg', '.ttf' )
doesn't change anything; my mina deployment also does a precompile, as suggested:
invoke :'rails:assets_precompile'
So how could this be solved?
I'm using Rails 4.1.

Rails: don't uglify HTML and CSS in test environment (using SLIM and Sass/Compass)?

I'm actively validating the HTML and CSS in request specs. Sadly, the error messages are very long because the HTML and CSS is uglified/compressed in test env.
I tried to remove the uglifier gem from the Gemfile, but this didn't work out. Do I miss some configuration option here? I can't find any for test.rb...
Update
I found that setting Slim::Engine.set_default_options pretty: true solved the problem for the HTML output.
The CSS is still compressed on one line though, I tried stuff like adding output_style = :nested to config/compass.css, setting Sass::Plugin.options[:style] = :expanded (raised an exception), add config.sass.output_style = :nested to test.rb, and setting # config.assets.css_compressor = nil also in test.rb. Didn't solve my problem.
Try setting this in test.rb:
config.assets.debug = true
In case you're using SLIM templating engine, set pretty: true:
Slim::Engine.set_default_options pretty: true
For more info see https://github.com/slim-template/slim#default-options.

Refinerycms on Heroku not working with AmazonS3 bucket

I try to setup Amazon S3 support to store images in the cloud with refinerycms.
I created the bucket at https://console.aws.amazon.com/s3/
I named it like the app 'bee-barcelona' and it says it is in region US Standard
In ~/config/initializers/refinery/images.rb I entered all the data (where 'xxx? stands for the actual keys I entered:
# Configure S3 (you can also use ENV for this)
# The s3_backend setting by default defers to the core setting for this but can be set just for images.
config.s3_backend = Refinery::Core.s3_backend
config.s3_bucket_name = ENV['bee-barcelona']
config.s3_access_key_id = ENV['xxx']
config.s3_secret_access_key = ENV['xxx']
config.s3_region = ENV['xxx']
Then I applied the changes to heroku with:
heroku config:add S3_KEY=xxx S3_SECRET=xxx S3_BUCKET=bee-barcelona S3_REGION=us-standard
But still, in the app I only get: "Sorry, something wen wrong" when I try to upload.
What did I miss?
What a sad error. I didn't think about that option till I went for a 10 km run…
I had the app set up to be "beekeeping"
My bucket on Amazon was named "bee-barcelona"
I did register the correct bucket in the app. Still refinery tried to keep on going to another persons bucket, named "beekeeping". With my secret key there was no way my files would end up there.
I created a new app and a new bucket, all with crazy names, BUT! They are the same on AmazonS3 and GIT!!!
No it works like a charm.
What a very rare situation...
The way I did it was as follows:
Create a bucket in region US-STANDARD!!!!!!!!!!
Did you see that? US-STANDARD, not oregon, not anywhere else.
Add gems to Gemfile
gem "fog"
gem "unf"
gem "dragonfly-s3_data_store"
In config/application.rb
config.assets.initialize_on_precompile = true
In config/environments/production.rb
Refinery::Core.config.s3_backend = true
In config/environments/development.rb
Refinery::Core.config.s3_backend = false
Configure S3 for heroku (production) and local storage for development. In config/initializers/refinery/core.rb
if Rails.env.production?
config.s3_backend = true
else
config.s3_backend = false
end
config.s3_bucket_name = ENV['S3_BUCKET']
config.s3_region = ENV['S3_REGION']
config.s3_access_key_id = ENV['S3_ACCESS_KEY']
config.s3_secret_access_key = ENV['S3_SECRET_KEY']
Add variables to heroku:
heroku config:add S3_ACCESS_KEY=xxxxxx S3_SECRET_KEY=xxxxxx S3_BUCKET=bucket-name-here S3_REGION=us-east-1
I had a lot of issues because I had before S3_REGION=us-standard. This is WRONG. Set your US-Standard bucket as shown:
S3_REGION=us-east-1
This worked flawlessly for me on Rails 4.2.1 and refinery 3.0.0. Also, make sure you are using the exact same names for the variables. Sometimes it says S3_KEY instead of S3_ACCESS_KEY or S3_SECRET instead of S3_SECRET_KEY. Just make sure you have the same ones in your files and your Heroku variables.

Rails asset pipeline Rails.application.assets.instance_variable_get('#environment') returns nil

I am trying to compile javascript dynamically and then adding it to the sprockets store so it is available. Everywhere I researched suggested the below code to register the javascript:
env = Rails.application.assets.is_a?(Sprockets::Index) ? Rails.application.assets.instance_variable_get('#environment') : Rails.application
Rails.application.config.assets.digests[file_name] = env[file_name].digest_path
in production, Rails.application.assets.instance_variable_get('#environment') always returns nil, is there something I am doing wrong? or should I be adding something else?
Rails.application.assets itself is an instance of Sprockets::Environment
#environment' is a variable of assets_manifest, that belongs to Rails.application, like this:
Rails.application.instance_variable_get('#assets_manifest').instance_variable_get('#environment')
I got similar problems with RAILS 3.2.15,
but it was Rails.application.assets returns nil
quiet_assets.rb:4:in': undefined method logger=' for nil:NilClass (NoMethodError)
the issued line was
Rails.application.assets.logger = Logger.new('logger.log')
I back to Rails console, and find Rails.application.assets just returned nil.
I fix this issue by this step:
include two gem in your Gemfile in case you don't have it.
gem 'sprockets'
gem 'sprockets-rails'
find the file cause the issue , and initial your assets object.
you can also put that in application.rb , in my case I put it in config/initializers/quiet_assets.rb , before I refer to logger.
add this line:
Rails.application.assets = Sprockets::Environment.new
before this issued line:
Rails.application.assets.logger = Logger.new('logger.log')
in application.rb , remember have activate assets pipeline .
config.assets.enabled = true
for production you may need to set config.assets.compile = true
hope this helps somehow
Build it yourself (which is needed for new versions)
env = Sprockets::Railtie.build_environment(Rails.application)

In a Rails 4 app, how do I compile the jQuery Mobile button icons?

I am developing a rails 4 app with jQuery Mobile and using the jquery_mobile_rails gem which means I don't need to install any of the jQuery files. My problem is that there are no icons for the buttons. These are displayed in development but not in production. I assume that I just need to compile them but where are they and how can I do that?
Since I am not using jQuery Mobile files directly, I don't have the option to to store the icons below them. The gem works in development mode but not in production mode. Can I assume that the gems contain the button icons internally? If so, I am at a loss to understand why they don't work in production mode.
jquery-rails (2.3.0)
jquery_mobile_rails (1.3.0)
There is a known issue currently with Rails 4 when precompiling assets per environment.
Try setting:
config.assets.precompile=true
in config/application.rb.
If that still doesn't work, try adding the following to config/application.rb:
config.assets.precompile += %w(*.png *.jpg *.jpeg *.gif)
I can't replicate the strange error you get when concatenating these files to config.assets.precompile. Can you try the answer to this question instead (replace the line above):
config.assets.precompile << Proc.new { |path|
if path =~ /\.(css|js|png|jpg|jpeg|gif)\z/
full_path = Rails.application.assets.resolve(path).to_path
app_assets_path = Rails.root.join('app', 'assets').to_path
vendor_assets_path = Rails.root.join('vendor', 'assets').to_path
if ((full_path.starts_with? app_assets_path) || (full_path.starts_with? vendor_assets_path)) && (!path.starts_with? '_')
puts "\t" + full_path.slice(Rails.root.to_path.size..-1)
true
else
false
end
else
false
end
}

Resources