rails app:update conflicts - cleanest way to select file content? - ruby-on-rails

I'm trying to upgrade from Rails 5.0 to Rails 5.1.1.
Running rails app:update results in various conflicts where Rails 5.1.1 has a file with the same name as Rails 5.0, and I'm asked what I want to do about it.
The 'diff' for 'development.rb' look like this:
config.cache_store = :memory_store
config.public_file_server.headers = {
- 'Cache-Control' => 'public, max-age=172800'
+ 'Cache-Control' => "public, max-age=#{2.days.seconds.to_i}"
}
else
config.action_controller.perform_caching = false
## -30,8 +30,6 ##
config.action_mailer.raise_delivery_errors = false
config.action_mailer.perform_caching = false
- host = 'localhost:3000' # Local server
- config.action_mailer.default_url_options = { host: host, protocol: 'http' }
# Print deprecation notices to the Rails logger.
config.active_support.deprecation = :log
So in this case, I'm happy for the 'Cache-Control' line to be changed, but want the other 2 lines ('host..', 'config...') left alone.
I know how to choose either the old file or the new file, but what do you do when you want parts of both? Do you just copy what you want to a separate file and paste in after the interactive process has finished, or is there a cleaner method?

As far as I can tell, the app:update process does not have an interactive way to edit. You just have to go back and edit it once the process is complete.
Looks like the easiest option for you in this case would be to choose your file in app:update and then copy the new cache control values in.

Related

How to set x frame default options in rails 3

In rails 4 this could be done under the config file if it already wasn't default.
config.action_dispatch.default_headers = { 'X-Frame-Options' => 'SAMEORIGIN' }
Is there a way to set the headers like that in rails 3.2.22.4? Thanks!
See these discussions:
https://github.com/rails/rails/issues/6311
https://github.com/rails/rails/pull/7302
default_headers configuration option (and 'SAMEORIGIN' on by default) was introduced in version 4.0. Before that headers can be manipulated with custom middlewares, or individually for each action as:
headers['X-Frame-Options'] = 'SAMEORIGIN'

How to disable Bullet in ActionMailer previews

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.

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.

Should Rails uglifier uglify (mangle) function names?

My .js files are compressed and variables mangled, but function names are not mangled (running latest Rails 3.2.8 and latest uglify 1.3.0 gem) on Heroku.
According to https://github.com/lautis/uglifier#usage the "mangle" option defaults to true. Below is my config.
From production.rb:
config.assets.compress = true
config.assets.js_compressor = :uglifier
I've also tried
config.assets.compress = true
config.assets.js_compressor = Uglifier.new(:mangle => true, :toplevel => true, :copyright => true)
but with no noticable difference.
As one commenter suggested, I did try changing contents of one my .js files, but didn't make a difference.
Example from output of the compressed precompiled .js file on Heroku:
show_slideout_notification=function(){jQuery(".slideout_notification").slideDown();var e=$(".slideout_notification .countdown
Seems that variable names are mangled, but function names are not.
Any ideas why function names are not mangled? Or is this not wanted behaviour as it would then be difficult to call the functions from my Rails/js code (i.e. javascript onclick events). Or would those onclick calls be renamed to the mangled name too if the function names were mangled?
Thanks :-)
Have you tried to modify the file? According to this the generation of asset files are based on file modification time. Maybe your settings not even being used.
Shouldn't it be like this?
config.assets.js_compressor = Uglifier.new(:mangle => { :toplevel => true }, :output => { :comments => :copyright })

Resources