samedi 6 juillet 2019

Deploy rails app to Heroku Error ArgumentError: Invalid option: harmony

I finished my blog and I'm trying to deploy it to heroku, but I keep getting this error.

I've tried changing my production.rb, Gemfile, and application.js which was advised from other people with the same problems, but none of it worked. Here's what I've done

I changed my production.rb to this

        config.assets.js_compressor = Uglifier.new(harmony: true)

Application.js:


        //= require jquery
        //= require jquery_ujs
        //= require turbolinks
        //= require ckeditor/init
        //= require_tree .

I've changed jquery_ujs to rails_ujs and it didn't change anything

Gemfile


ruby '2.5.1'

group :production do
  gem 'pg'
  gem 'rails_12factor'
end

group :development do
  gem 'sqlite3', '~> 1.3.6'
end

gem 'rails', '~> 5.2.1'
gem 'puma', '~> 3.11'
gem 'sass-rails', '~> 5.0'
gem 'uglifier', '>= 1.0.3', require: 'uglifier'
gem 'coffee-rails', '~> 4.2'
gem 'turbolinks', '~> 5'
gem 'jbuilder', '~> 2.5'
gem 'bootsnap', '>= 1.1.0', require: false
gem 'redcarpet', '~> 3.4'
gem 'pygments.rb', '~> 1.2', '>= 1.2.1'
gem 'friendly_id', '~> 5.2', '>= 5.2.4'
gem 'will_paginate', '~> 3.1', '>= 3.1.6'
gem 'mail_form', '~> 1.5', '>= 1.5.1'
gem 'devise', '~> 4.2'
gem "paperclip", "~> 6.0.0"
gem 'ckeditor', '~> 4.1'
gem 'meta-tags', '~> 2.1'
gem 'rb-readline', '~> 0.5.3'
gem 'cancancan'
gem 'carrierwave'
gem 'mini_magick'
gem 'social-share-button'





group :development, :test do
  gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
end
group :development do
  gem 'web-console', '>= 3.3.0'
  gem 'listen', '>= 3.0.5', '< 3.2'
  gem 'spring'
  gem 'spring-watcher-listen', '~> 2.0.0'
end
group :test do
  gem 'capybara', '>= 2.15'
  gem 'selenium-webdriver'
  gem 'chromedriver-helper'
end
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]


Here is my terminal

remote:        Running: rake assets:precompile
remote:        rake aborted!
remote:        ArgumentError: Invalid option: harmony
remote:        /tmp/build_08823881a010f97ecfcad2f83b760e2b/vendor/bundle/ruby/2.5.0/gems/uglifier-2.7.2/lib/uglifier.rb:168:in `block in initialize'
remote:        /tmp/build_08823881a010f97ecfcad2f83b760e2b/vendor/bundle/ruby/2.5.0/gems/uglifier-2.7.2/lib/uglifier.rb:167:in `each'
remote:        /tmp/build_08823881a010f97ecfcad2f83b760e2b/vendor/bundle/ruby/2.5.0/gems/uglifier-2.7.2/lib/uglifier.rb:167:in `initialize'
remote:        /tmp/build_08823881a010f97ecfcad2f83b760e2b/config/environments/production.rb:26:in `new'
remote:        /tmp/build_08823881a010f97ecfcad2f83b760e2b/config/environments/production.rb:26:in `block in <main>'
remote:        /tmp/build_08823881a010f97ecfcad2f83b760e2b/vendor/bundle/ruby/2.5.0/gems/railties-5.2.1/lib/rails/railtie.rb:216:in `instance_eval'
remote:        /tmp/build_08823881a010f97ecfcad2f83b760e2b/vendor/bundle/ruby/2.5.0/gems/railties-5.2.1/lib/rails/railtie.rb:216:in `configure'
remote:        /tmp/build_08823881a010f97ecfcad2f83b760e2b/config/environments/production.rb:1:in `<main>'
remote:        /tmp/build_08823881a010f97ecfcad2f83b760e2b/vendor/bundle/ruby/2.5.0/gems/bootsnap-1.3.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require'
remote:        /tmp/build_08823881a010f97ecfcad2f83b760e2b/vendor/bundle/ruby/2.5.0/gems/bootsnap-1.3.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `block in require_with_bootsnap_lfi'
remote:        /tmp/build_08823881a010f97ecfcad2f83b760e2b/vendor/bundle/ruby/2.5.0/gems/bootsnap-1.3.1/lib/bootsnap/load_path_cache/loaded_features_index.rb:65:in `register'
remote:        /tmp/build_08823881a010f97ecfcad2f83b760e2b/vendor/bundle/ruby/2.5.0/gems/bootsnap-1.3.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:20:in `require_with_bootsnap_lfi'
remote:        /tmp/build_08823881a010f97ecfcad2f83b760e2b/vendor/bundle/ruby/2.5.0/gems/bootsnap-1.3.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:29:in `require'
remote:        /tmp/build_08823881a010f97ecfcad2f83b760e2b/vendor/bundle/ruby/2.5.0/gems/activesupport-5.2.1/lib/active_support/dependencies.rb:287:in `block in require'
remote:        /tmp/build_08823881a010f97ecfcad2f83b760e2b/vendor/bundle/ruby/2.5.0/gems/activesupport-5.2.1/lib/active_support/dependencies.rb:253:in `load_dependency'
remote:        /tmp/build_08823881a010f97ecfcad2f83b760e2b/vendor/bundle/ruby/2.5.0/gems/activesupport-5.2.1/lib/active_support/dependencies.rb:287:in `require'
remote:        /tmp/build_08823881a010f97ecfcad2f83b760e2b/vendor/bundle/ruby/2.5.0/gems/railties-5.2.1/lib/rails/engine.rb:602:in `block (2 levels) in <class:Engine>'
remote:        /tmp/build_08823881a010f97ecfcad2f83b760e2b/vendor/bundle/ruby/2.5.0/gems/railties-5.2.1/lib/rails/engine.rb:601:in `each'
remote:        /tmp/build_08823881a010f97ecfcad2f83b760e2b/vendor/bundle/ruby/2.5.0/gems/railties-5.2.1/lib/rails/engine.rb:601:in `block in <class:Engine>'
remote:        /tmp/build_08823881a010f97ecfcad2f83b760e2b/vendor/bundle/ruby/2.5.0/gems/railties-5.2.1/lib/rails/initializable.rb:32:in `instance_exec'
remote:        /tmp/build_08823881a010f97ecfcad2f83b760e2b/vendor/bundle/ruby/2.5.0/gems/railties-5.2.1/lib/rails/initializable.rb:32:in `run'
remote:        /tmp/build_08823881a010f97ecfcad2f83b760e2b/vendor/bundle/ruby/2.5.0/gems/railties-5.2.1/lib/rails/initializable.rb:61:in `block in run_initializers'
remote:        /tmp/build_08823881a010f97ecfcad2f83b760e2b/vendor/bundle/ruby/2.5.0/gems/railties-5.2.1/lib/rails/initializable.rb:50:in `each'
remote:        /tmp/build_08823881a010f97ecfcad2f83b760e2b/vendor/bundle/ruby/2.5.0/gems/railties-5.2.1/lib/rails/initializable.rb:50:in `tsort_each_child'
remote:        /tmp/build_08823881a010f97ecfcad2f83b760e2b/vendor/bundle/ruby/2.5.0/gems/railties-5.2.1/lib/rails/initializable.rb:60:in `run_initializers'
remote:        /tmp/build_08823881a010f97ecfcad2f83b760e2b/vendor/bundle/ruby/2.5.0/gems/railties-5.2.1/lib/rails/application.rb:361:in `initialize!'
remote:        /tmp/build_08823881a010f97ecfcad2f83b760e2b/config/environment.rb:5:in `<main>'
remote:        /tmp/build_08823881a010f97ecfcad2f83b760e2b/vendor/bundle/ruby/2.5.0/gems/bootsnap-1.3.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require'
remote:        /tmp/build_08823881a010f97ecfcad2f83b760e2b/vendor/bundle/ruby/2.5.0/gems/bootsnap-1.3.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `block in require_with_bootsnap_lfi'
remote:        /tmp/build_08823881a010f97ecfcad2f83b760e2b/vendor/bundle/ruby/2.5.0/gems/bootsnap-1.3.1/lib/bootsnap/load_path_cache/loaded_features_index.rb:65:in `register'
remote:        /tmp/build_08823881a010f97ecfcad2f83b760e2b/vendor/bundle/ruby/2.5.0/gems/bootsnap-1.3.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:20:in `require_with_bootsnap_lfi'
remote:        /tmp/build_08823881a010f97ecfcad2f83b760e2b/vendor/bundle/ruby/2.5.0/gems/bootsnap-1.3.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:29:in `require'
remote:        /tmp/build_08823881a010f97ecfcad2f83b760e2b/vendor/bundle/ruby/2.5.0/gems/activesupport-5.2.1/lib/active_support/dependencies.rb:287:in `block in require'
remote:        /tmp/build_08823881a010f97ecfcad2f83b760e2b/vendor/bundle/ruby/2.5.0/gems/activesupport-5.2.1/lib/active_support/dependencies.rb:253:in `load_dependency'
remote:        /tmp/build_08823881a010f97ecfcad2f83b760e2b/vendor/bundle/ruby/2.5.0/gems/activesupport-5.2.1/lib/active_support/dependencies.rb:287:in `require'
remote:        /tmp/build_08823881a010f97ecfcad2f83b760e2b/vendor/bundle/ruby/2.5.0/gems/railties-5.2.1/lib/rails/application.rb:337:in `require_environment!'
remote:        /tmp/build_08823881a010f97ecfcad2f83b760e2b/vendor/bundle/ruby/2.5.0/gems/railties-5.2.1/lib/rails/application.rb:520:in `block in run_tasks_blocks'
remote:        /tmp/build_08823881a010f97ecfcad2f83b760e2b/vendor/bundle/ruby/2.5.0/gems/sprockets-rails-3.2.1/lib/sprockets/rails/task.rb:62:in `block (2 levels) in define'
remote:        /tmp/build_08823881a010f97ecfcad2f83b760e2b/vendor/bundle/ruby/2.5.0/gems/rake-12.3.1/exe/rake:27:in `<top (required)>'
remote:        Tasks: TOP => environment
remote:        (See full trace by running task with --trace)
remote: 
remote:  !
remote:  !     Precompiling assets failed.
remote:  !
remote:  !     Push rejected, failed to compile Ruby app.
remote: 
remote:  !     Push failed
remote: Verifying deploy...
remote: 
remote: !   Push rejected to obscure-harbor-21335.

Any help would be appreciated thank you

How to convert return string from webservice to pdf file

I need to convert string which i am getting from webservice to pdf. Basically webservice is to download file, but i want to use it like download and save file to my database from backend.

Concern is sample pdf file returns is in string format like below

"%PDF-1.3\r\n%\xE2\xE3\xCF\xD3\r\n\r\n1 0 obj\r\n<<\r\n/Type /Catalog\r\n/Outlines 2 0 R\r\n/Pages 3 0 R\r\n>>\r\nendobj\r\n\r\n2 0 obj\r\n<<\r\n/Type /Outlines\r\n/Count 0\r\n>>\r\nendobj\r\n\r\n3 0 obj\r\n<<\r\n/Type /Pages\r\n/Count 2\r\n/Kids [ 4 0 R 6 0 R ] \r\n>>\r\nendobj\r\n\r\n4 0 obj\r\n<<\r\n/Type /Page\r\n/Parent 3 0 R\r\n/Resources <<\r\n/Font <<\r\n/F1 9 0 R \r\n>>\r\n/ProcSet 8 0 R\r\n>>\r\n/MediaBox [0 0 612.0000 792.0000]\r\n/Contents 5 0 R\r\n>>\r\nendobj\r\n\r\n5 0 obj\r\n<< /Length 1074 >>\r\nstream\r\n2 J\r\nBT\r\n0 0 0 rg\r\n/F1 0027 Tf\r\n57.3750 722.2800 Td\r\n( A Simple PDF File ) Tj\r\nET\r\nBT\r\n/F1 0010 Tf\r\n69.2500 688.6080 Td\r\n( This is a small demonstration .pdf file - ) Tj\r\nET\r\nBT\r\n/F1 0010 Tf\r\n69.2500 664.7040 Td\r\n( just for use in the Virtual Mechanics tutorials. More text. And more ) Tj\r\nET\r\nBT\r\n/F1 0010 Tf\r\n69.2500 652.7520 Td\r\n( text. And more text. And more text. And more text. ) Tj\r\nET\r\nBT\r\n/F1 0010 Tf\r\n69.2500 628.8480 Td\r\n( And more text. And more text. And more text. And more text. And more ) Tj\r\nET\r\nBT\r\n/F1 0010 Tf\r\n69.2500 616.8960 Td\r\n( text. And more text. Boring, zzzzz. And more text. And more text. And ) Tj\r\nET\r\nBT\r\n/F1 0010 Tf\r\n69.2500 604.9440 Td\r\n( more text. And more text. And more text. And more text. And more text. ) Tj\r\nET\r\nBT\r\n/F1 0010 Tf\r\n69.2500 592.9920 Td\r\n( And more text. And more text. ) Tj\r\nET\r\nBT\r\n/F1 0010 Tf\r\n69.2500 569.0880 Td\r\n( And more text. And more text. And more text. And more text. And more ) Tj\r\nET\r\nBT\r\n/F1 0010 Tf\r\n69.2500 557.1360 Td\r\n( text. And more text. And more text. Even more. Continued on page 2 ...) Tj\r\nET\r\nendstream\r\nendobj\r\n\r\n6 0 obj\r\n<<\r\n/Type /Page\r\n/Parent 3 0 R\r\n/Resources <<\r\n/Font <<\r\n/F1 9 0 R \r\n>>\r\n/ProcSet 8 0 R\r\n>>\r\n/MediaBox [0 0 612.0000 792.0000]\r\n/Contents 7 0 R\r\n>>\r\nendobj\r\n\r\n7 0 obj\r\n<< /Length 676 >>\r\nstream\r\n2 J\r\nBT\r\n0 0 0 rg\r\n/F1 0027 Tf\r\n57.3750 722.2800 Td\r\n( Simple PDF File 2 ) Tj\r\nET\r\nBT\r\n/F1 0010 Tf\r\n69.2500 688.6080 Td\r\n( ...continued from page 1. Yet more text. And more text. And more text. ) Tj\r\nET\r\nBT\r\n/F1 0010 Tf\r\n69.2500 676.6560 Td\r\n( And more text. And more text. And more text. And more text. And more ) Tj\r\nET\r\nBT\r\n/F1 0010 Tf\r\n69.2500 664.7040 Td\r\n( text. Oh, how boring typing this stuff. But not as boring as watching ) Tj\r\nET\r\nBT\r\n/F1 0010 Tf\r\n69.2500 652.7520 Td\r\n( paint dry. And more text. And more text. And more text. And more text. ) Tj\r\nET\r\nBT\r\n/F1 0010 Tf\r\n69.2500 640.8000 Td\r\n( Boring.  More, a little more text. The end, and just as well. ) Tj\r\nET\r\nendstream\r\nendobj\r\n\r\n8 0 obj\r\n[/PDF /Text]\r\nendobj\r\n\r\n9 0 obj\r\n<<\r\n/Type /Font\r\n/Subtype /Type1\r\n/Name /F1\r\n/BaseFont /Helvetica\r\n/Encoding /WinAnsiEncoding\r\n>>\r\nendobj\r\n\r\n10 0 obj\r\n<<\r\n/Creator (Rave \\(http://www.nevrona.com/rave\\))\r\n/Producer (Nevrona Designs)\r\n/CreationDate (D:20060301072826)\r\n>>\r\nendobj ... 

Please suggest.

mercredi 3 juillet 2019

Override column_names for Model Class

I am customizing my Active admin with below code

ActiveAdmin.register Question do
  index do
    Question.column_names.each do |c|
      column c.to_sym
    end
  end
end

However, I don't want to show created_at and updated_at fields. How can I override this method for all of my Model Class to hide those two fields?

mardi 2 juillet 2019

How to write ActiveJob log into a different file

I want to find a way to log ActiveJob logs to a different log other than the production.log

I am on a rails 4.2.5 project. The project used a lot of ActiveJob and DelayedJob. they write into same log, making the log very messy and hard to debug. I want to write the job log to a different file, so I did this in initializers/delayed_job.rb:

delayed_job_logger = Logger.new(File.join(Rails.root, 'log', "delayed_job_# {Rails.env}.log"), 10, 100 * 1024 * 1024)
Delayed::Worker.logger = delayed_job_logger
ActiveJob::Base.logger = delayed_job_logger

After the configuration, the delayed job logs is doing well. it did write to delayed_job_production.log

I, [2019-07-02T12:33:36.664242 #14335] INFO -- : 2019-07-02T12:33:36-0500: [Worker(delayed_job.6 host:pioneer3-app-production pid:14335)] Job ActiveJob::QueueAdapters::DelayedJobAdapter::JobWrapper (id=60672406) (queue=TfrToP2InTimeJob) COMPLETED after 0.0098

but the ActiveJob log is still mixing in the production.log

I, [2019-07-02T12:33:42.091068 #13730] INFO -- : [ActiveJob] [PipelineRollMonthJob] [93fc7600-2ba9-48eb-a6bd-729d3e830114] Performed PipelineRollMonthJob from DelayedJob(PipelineRollMonthJob) in 5.53ms

how can I fix the activejob log?

lundi 1 juillet 2019

joins on tables without relation in rails

What's the work around of not being able to use joins on tables that don't have relation?

E.g:

class Student
end

class Lesson
end


There is no explicit correlation between Student and Lesson, however, in DB, we have implicit correlation: students.lesson_id and lessons.id.

Using pure SQL can join these two tables, however, using joins provided by rails like this:

Student.joins(:lesson).where('student.lesson_id=lesson.id')

will throw "Association named 'lesson' was not found on Student; perhaps you misspelled it?"

I'm looking for work around with below requirements:

  • In order to improve the efficiency, using RDBMS queries will be ideal. (Rails sort_by, find etc are not)
  • In order to improve readability, raw SQL is not ideal.

Is there any work around out there? Thanks!

how to disable checkbox on condition?

I am trying to create a spreadsheet on index page to display items with checkbox and if validated - the checkbox will be disabled so that people won't mis-ticked it. can you help?

In app/views/scooties_coupons/index.html.erb

<table class="table table-hover">

<h1>Scooties Coupons</h1>

<%= form_with(url: validate_coupons_path, method: 'patch') do |f| %>
  <table>
    <thead>
      <tr>
        <th>Valid</th>
        <th>Coupon</th>
        <th>Redeemed</th>
        <th>First name</th>
        <th>Surname</th>
        <th>email</th>
        <th>occupation</th>
        <th>validation</th>
        <th colspan="3"></th>
      </tr>
    </thead>

    <tbody>
      <% @scooties_coupons.each do |scooties_coupon| %>
        <tr>
          <td>
            <%= fields_for('scooties_coupons[]', scooties_coupon) do |cf|
              cf.check_box(:validated)
            end %>
          </td>
          <td><%= scooties_coupon.coupon %></td>
          <td><%= scooties_coupon.redeemed %></td>
          <td><%= scooties_coupon.first_name %></td>
          <td><%= scooties_coupon.surname %></td>
          <td><%= scooties_coupon.email %></td>
          <td><%= scooties_coupon.occupation %></td>

        </tr>
      <% end %>
    </tbody>
  </table>
  <%= f.submit %>
<% end %>

<br>

</table>


in app/controllers/scotties_coupons_controller.rb:


def set_valid_coupons
  to_valid = params[:scooties_coupons].select do |id, attrs|
    attrs[:validated] == '1'
  end
  to_not_valid = params[:scooties_coupons].reject do |id, attrs|
    attrs[:validated] == '1'
  end
  ScootiesCoupon.transaction do
    ScootiesCoupon.where(id: to_valid.keys, validated: false).update_all(
      validated:true)
    ScootiesCoupon.where(id: to_not_valid.keys, validated: true).update_all(
      validated:false)
  end
  redirect_to action: :index, notice: 'Validations updated'
end


How do I customize a view generated by a Comfy CMS Page?

In my Rails 3.2 app, I am using comfortable_mexican_sofa 1.8.

I have created some 'CMS Pages' within the CMS admin (some static pages like 'About Us', 'Contact Us', etc.). All of these pages are populated by the fields within the CMS Admin section.

But I can't figure out how to customize the template so that it renders the about us correctly.

Here is the log:

Started GET "/about" for 127.0.0.1 at 2019-07-01 01:42:05 -0500
Processing by CmsContentController#render_html as HTML
  Parameters: {"cms_path"=>"about"}
   (1.3ms)  SELECT COUNT(*) FROM "admins" WHERE (admins.superadmin = 't')
   (0.7ms)  SELECT COUNT(*) FROM "cms_sites" 
  Cms::Site Load (0.4ms)  SELECT "cms_sites".* FROM "cms_sites" LIMIT 1
  Cms::Page Load (1.5ms)  SELECT "cms_pages".* FROM "cms_pages" WHERE "cms_pages"."site_id" = 1 AND "cms_pages"."is_published" = 't' AND "cms_pages"."full_path" = '/about' ORDER BY cms_pages.position LIMIT 1
  Cms::Layout Load (0.8ms)  SELECT "cms_layouts".* FROM "cms_layouts" WHERE "cms_layouts"."id" = 5 ORDER BY cms_layouts.position LIMIT 1
  Cms::Block Load (1.0ms)  SELECT "cms_blocks".* FROM "cms_blocks" WHERE "cms_blocks"."page_id" = 9 AND "cms_blocks"."identifier" = 'blurb' LIMIT 1
  Cms::Page Load (0.8ms)  SELECT "cms_pages".* FROM "cms_pages" WHERE "cms_pages"."id" = 9 ORDER BY cms_pages.position LIMIT 1
  CACHE (0.0ms)  SELECT "cms_layouts".* FROM "cms_layouts" WHERE "cms_layouts"."id" = 5 ORDER BY cms_layouts.position LIMIT 1
  Cms::Layout Load (0.8ms)  SELECT "cms_layouts".* FROM "cms_layouts" WHERE "cms_layouts"."id" = 2 ORDER BY cms_layouts.position LIMIT 1
  Cms::Block Load (1.3ms)  SELECT "cms_blocks".* FROM "cms_blocks" WHERE "cms_blocks"."page_id" = 9
  Rendered inline template (1.5ms)
  Rendered partials/cms/pages/_header.html.haml (78.3ms)
  Cms::Page Load (0.7ms)  SELECT "cms_pages".* FROM "cms_pages" WHERE "cms_pages"."id" = 1 ORDER BY cms_pages.position LIMIT 1
  Rendered inline template within layouts/cms_inside (108.3ms)
  Cms::Page Load (1.3ms)  SELECT "cms_pages".* FROM "cms_pages" WHERE "cms_pages"."site_id" = 1 AND (parent_id IS NULL) ORDER BY cms_pages.position LIMIT 1
  Cms::Page Load (0.7ms)  SELECT "cms_pages".* FROM "cms_pages" WHERE "cms_pages"."parent_id" = 1 AND "cms_pages"."is_published" = 't' ORDER BY cms_pages.position OFFSET 1
  Rendered shared/_navbar.html.erb (13.5ms)
  Cms::Snippet Load (1.2ms)  SELECT "cms_snippets".* FROM "cms_snippets" WHERE "cms_snippets"."site_id" = 1 AND "cms_snippets"."identifier" = 'footer_contact' ORDER BY cms_snippets.position LIMIT 1
  Rendered inline template (1.5ms)
  Rendered shared/_footer.html.erb (13.6ms)
Completed 200 OK in 386.2ms (Views: 324.8ms | ActiveRecord: 12.5ms)

I don't have an 'about' path declared in my routes.rb, nor an about_controller and therefore I don't have a app/views/cms/pages/about.html.erb or anything like that.

I do have things like layouts/cms_inside which renders correctly, but it has a yield block that just renders the data collected from the text fields in the CMS Admin.

I have checked the documents at the GH repo, but it isn't clear about how to customize these generated pages.

Thoughts?