Thursday, January 19, 2017

Rails render partial from sub-directory | Fixed issues

Rails render partial from sub-directory | Fixed issues


Rails render partial from sub-directory

Posted: 19 Jan 2017 08:31 AM PST

I've just implemented the Devise Invitable gem in my rails app and now I'm having an issue getting my partials to render. I imagine it's because of absolute vs. relative paths.

I'm hesitant to change much in my application.rb since all of my other views rely on the partials that are being rendered. So, is there another way to make this all work?

Here is the directory tree:

app/   -controllers/   ---application_controller.rb   ---users/   -----invitations_controller.rb   -views/   ---layouts/   -----application.html.erb   -----_back_buttons.html.erb   -----_footer.html.erb   -----_navigation.html.erb   ---users/   -----invitations/   -------new.html.erb   -------edit.html.erb  

In my application.rb file, I'm currently rendering views & partials with:

<%= render partial: 'layouts/navigation' %>  <%= render partial: 'layouts/topnav' %>  <%= render partial: 'layouts/tour' %>    <%= yield %>    <%= render partial: 'layouts/footer' %>  <%= javascript_include_tag 'footermanifest' %>  

And in my new view views/users/invitations/new.html.erb:

<%= render partial: "/layouts/back_button" %>  ... the form  

Notice the absolute reference to the partial here (/)

This loads the layouts/_back_button.html.erb fine, but none of the other partials in application.html.erb load. Basically, I have a pretty empty page with a form (courtesy of application.html.erb).

Am I doing something wrong in how I've nested the views/users/invitations/new.html.erb or something else?

Why javascript stop working when reset filterrific or change page?

Posted: 19 Jan 2017 08:32 AM PST

PROBLEM

Javascript of my web application built in Ruby-2.3.3, Rails 4.2.7.1 stopped working when I reset filters of Filterrific 2.1.2 or change page, with pagination provided by Will_paginate 3.1.5 and Will_paginate-bootstrap 1.0.1.

I notice that when Turbolinks 5.0.1 is disabled, the problem was gone.

QUESTION

Anyone has a solution that's not involve disable Turbolinks? I also tried the gem jquery-turbolinks and get no results.

Version in CarrierWave is always being generated

Posted: 19 Jan 2017 08:23 AM PST

I want to generate a zipped version of my files with CarrierWave only if one condition is passed, like the documentation specifies.

The thing is that the version is always being generated, even if I return false from the conditional function.

  version :zipped, if: :is_output_file? do      def full_filename (for_file = model.file.file)        output_extension = "zip"        "#{for_file.chomp(".stl")}.#{output_extension}"      end    end      def is_output_file? file      false    end  

(Note that I don't do any processing because the zipped file is already uploaded to S3 by other application, but it doesn't matter for the case).

Then when I check the results on the console, a "zipped" version was generated as you can see (the output was cutted because it was too long)...

irb(main):009:0> PrintingFile.last.file

=> #<PrintingFileUploader:0x798f348 @model=#<PrintingFile id: 10, name: (...) , @versions={:zipped=>#<PrintingFileUploader::Uploader56093724:0x798ed90 @model=#<PrintingFile id: 10, name: (...)  

Ambiguous column

Posted: 19 Jan 2017 08:26 AM PST

I have a scope in my model

scope :created_this_week, -> { where("created_at >= ?", Time.zone.now.beginning_of_week) }  

Which correctly returns the amount of vacancies create that week.

Now I need to see how many of those vacancies have a matching (can have multiple matchings per vacancy) with a state of either "applied" or "accepted"

So I tried to do following:

Vacancy.created_this_week.includes(:matchings)  .where(matchings: {state: ["accepted", "applied"]})  

But I get following error

PG::AmbiguousColumn: ERROR:  column reference "created_at" is ambiguous  

Rails API: Cannot whitelist JSON field attribute

Posted: 19 Jan 2017 08:22 AM PST

I'm building a rails API with a model containing an attribute data of JSON type. (PSQL)

But when I try to post something like this

{ model: { name: 'Hello', data: { a: 1, b: 2 } } }  

Rails thinks a and b are the attributes of a nested data association... It considers then they are unpermitted params. The thing is, { a: 1, b: 2 } is the value of my field data.

How to provide JSON value to an attribute ?

Rails Common Assets Except for one controller

Posted: 19 Jan 2017 08:24 AM PST

I've not been able to find the answer to this. I can load controller specific assets but that would be cumbersome as I add new controllers to my app (been there).

Is there a way to have common assets ie:

require tree .   

But then have one controller which ignores those assets and loads only its own?

I want a home page that has unique css and js. Then once logged in (devise) the other assets are used because it would be a dashboard once logged in.

How to make svgxuse.js work with turbolinks

Posted: 19 Jan 2017 08:13 AM PST

I have just spend half of a day trying to figure it out why my SVG sprite won't load in Internet explorer after clicking turbolink.

As you probably know, you need some javascript to render the SVGs in IE, I use svgxuse.js (packed with Icomoons svg sprite).

So, if you are facing similiar issue with turbolinks and svgxuse.js you have to edit only two lines in svgxuse.js file. Just scroll to the end of the file and find:

window.addEventListener('load', function winLoad() {      window.removeEventListener('load', winLoad, false); // to prevent memory leaks      tid = setTimeout(checkUseElems, 0);  }, false);  

And change this to:

window.addEventListener('turbolinks:load', function winLoad() {      window.removeEventListener('turbolinks:load', winLoad, false); // to prevent memory leaks      tid = setTimeout(checkUseElems, 0);  }, false);  

I have just wanted to share my "discovery" as I haven't found anything about it on Google.

Alter heroku's config var in my rails app

Posted: 19 Jan 2017 07:58 AM PST

I intent to change it when the admin user log in and log out. Is it possible and how can I do it?

select2 doesn't put selected at the top

Posted: 19 Jan 2017 08:26 AM PST

i'm trying out this plug, select2. i get the search, but upon selecting a return, it doesn't show at the top. if somebody could pinpoint the error, i would be much appreciative.

... more details would include the fact that :recipients is an array type, I'm not sure if that would affect it (I was going to upgrade to hstore once i got it going, to save each selection (searchable_type and searchable_id)).

 <%= simple_form_for(plate, remote: true, format: :js) do |f| %>          <%= f.input :recipients, input_html:  { id: "recipients" } %>  

and the script:

<script>     function templateResult (item) {      return item.text;    }      function templateSelection (item) {      return item.text;    }      $("#recipients").select2({      placeholder: "To:",      multiple: true,      ajax: {        url: "/plates",        dataType: 'json',        delay: 250,        data: function (params) {          return {            q: params.term, // search term            page: params.page          };        },        processResults: function (data, params) {          // parse the results into the format expected by Select2          // since we are using custom formatting functions we do not need to          // alter the remote JSON data, except to indicate that infinite          // scrolling can be used          params.page = params.page || 1;          return {            results: $.map(data, function(el) {                return {                  text: el.searchable_type + ", id: " + el.searchable_id,                  id: el.searchable_id                };            }),            pagination: {              more: (params.page * 30) < data.total_count            }          };        },        cache: true      },      escapeMarkup: function (markup) { return markup; }, // let our custom formatter work      minimumInputLength: 1,      templateResult: templateResult, // omitted for brevity, see the source of this page      templateSelection: templateSelection// omitted for brevity, see the source of this page    });    </script>  

How to set cookie without encryption [Rails] [duplicate]

Posted: 19 Jan 2017 07:43 AM PST

This question already has an answer here:

I have one problem. I know how to set cookie in a controller:

cookies.signed["@cookieName"] = {      value: @cookieValue,      :expires => 1.year.from_now  }  

But there is a problem. This is going to encrypt cookie. But my cookie is already encrypted, so I need to set exact value that I get from another method. Long, encrypted key.

Is it possible?

Best Practice for a database that continues to expand with more tables

Posted: 19 Jan 2017 08:11 AM PST

I am a Ruby on Rails application developer and have helped with the creation of a database "college_a", containing information about the college I work for.

Initially, "college_a" contained tables for apps, apps_auths, and apps_roles. Over the past years it has expanded to contain tables for employees, job info, and supervisors ... all in the "college_a" database. I am looking at saving data about email accounts and am wondering if there are any drawbacks to continuing to add more tables to "college_a" or should I start looking at creating a new database representing data on email accounts which will need to reference data from the "college_a.people" table.

Not having experience with the maintenance/usage of an ever expanding database or needing to query multiple databases to gather needed data, is why I am asking if there are any negatives from continuing to add more tables to "college_a" database?

Thank you.

disable Rubocop complaint about method

Posted: 19 Jan 2017 07:34 AM PST

I have a method that goes like this return if amount == 0 and rubocop is complaining that it should be like return if amount.zero?. How can I have it skip over that method? Here is my .rubocop.yml:

rubocop

StringLiterals:    EnforcedStyle: double_quotes    Enabled: true    Style/FrozenStringLiteralComment:    Enabled: false    Style/TrailingCommaInLiteral:    Enabled: false    Style/TrailingCommaInArguments:    Enabled: false    Style/CaseEquality:    Enabled: false    Documentation:    Description: "Document classes and non-namespace modules."    Enabled: false    Metrics/MethodLength:    CountComments: false    Max: 15    Rails/Delegate:    Enabled: false    AllCops:    Exclude:      - db/**/*      - config/**/*      - script/**/*      - vendor/**/*      - bin/**/*      - Rakefile      - spec/spec_helper.rb      - spec/rails_helper.rb      - spec/teaspoon_env.rb      TargetRubyVersion: 2.3    Rails:    Enabled: true  

submit_ticket_payment.rb

def call    return if amount == 0    Stripe::Charge.create(      amount: amount,      currency: "usd",      description: event_name,      receipt_email: context.rsvp.email,      source: context.token,      statement_descriptor: event_name    )  rescue Stripe::StripeError    context.fail!  end  

So basically how can I have it not care about that particular instance?

How to customize signup and login process in refinery process

Posted: 19 Jan 2017 07:24 AM PST

I have 5 admins in refinery cms. I want to restrict them to perform all actions meanz I want to add role in admin.

Is it possible? How can I do that?

learn-rails bundle install error parsing Gemfile

Posted: 19 Jan 2017 08:22 AM PST

I'm totally noob, and doing the Learn Ruby On Rails Book One from start. I've got stuck a couple of times, but have resolved it myself by google, stackoverflow, etc... (I don't want to be a burden) But this I can't get by. I'm on the Gemfile "chapter". First I just tried to copy the exact as it is in the book:

source 'https://rubygems.org' ruby '2.0.0'  gem 'rails', '4.0.1'   # Rails defaults  gem 'sqlite3'  gem 'sass-rails', '~> 4.0.0' gem 'uglifier', '>= 1.3.0'  gem 'coffee-rails', '~> 4.0.0' gem 'jquery-rails'  gem 'turbolinks'  gem 'jbuilder', '~> 1.2'   # learn-rails  gem 'activerecord-tableless'  gem 'compass-rails', '~> 2.0.alpha.0' gem 'figaro'  gem 'gibbon'  gem 'google_drive'  gem 'high_voltage'  gem 'simple_form'  gem 'zurb-foundation'  group :development do  gem 'better_errors' gem 'quiet_assets' gem 'rails_layout'  end  

Which gives me this result:

[!] There was an error parsing `Gemfile`: syntax error, unexpected tIDENTIFIER, expecting gem 'rails', '4.0.1'...https://rubygems.org' ruby '2.0.0'  ...                               ^. Bundler cannot continue.     #  from /Users/MYUSERNAME/Projects/learn-rails/Gemfile:1   #  -------------------------------------------  end 'better_errors' gem 'quiet_assets' gem 'rails_layout'  

I then tried to change a few things like versions and so on, like this:

source 'https://rubygems.org'  ruby '2.3.3'  gem 'rails', '5.0.1'     # Rails defaults  gem 'sqlite3'  gem 'sass-rails', '~> 5.0'  gem 'uglifier', '>= 1.3.0'  gem 'coffee-rails', '~> 4.2'  gem 'jquery-rails'  gem 'turbolinks'  gem 'jbuilder', '~> 2.5'     # learn-rails  gem 'activerecord-tableless'  gem 'compass-rails', '~> 2.0.alpha.0'  gem 'figaro'  gem 'gibbon'  gem 'google_drive'  gem 'high_voltage'  gem 'simple_form'  gem 'zurb-foundation'  group :development do   gem 'better_errors'   gem 'quiet_assets'    gem 'rails_layout'  end  

This gives me this result:

[!] There was an error parsing `Gemfile`: no .<digit> floating literal anymore; put 0 before dot - ruby '2.3.3'            ^  /Users/MYUSERNAME/Projects/learn-rails/Gemfile:2: syntax error, unexpected tFLOAT, expecting '('  ruby '2.3.3'               ^. Bundler cannot continue.     #  from /Users/MYUSERNAME/Projects/learn-rails/Gemfile:2   #  -------------------------------------------   #  source 'https://rubygems.org'   >  ruby '2.3.3'   #  gem 'rails', '5.0.1'   #  -------------------------------------------  

I've tried a few things I found when searching, like changing the ' to " on the ruby version, putting a '0.2.3.3' or just '.2.3.3', doing a bundle update, etc. I don't know what the the "no . floatin..." means? Or what the "expecting '('" is?

I really have searched and tried various solutions (got like 4-5 different saved "Gemfile" from trying whatever I found on the net). Sorry if this just takes up space in the interwebs, but I just don't get it. If the original (from the book) doesn't even work, then why is it even there?

(I only changed my personal name to MYUSERNAME here, because it's my full, actual name, and maybe I'm paranoid but may so be. So that is not a fault)

Thanks, Ethonrails

Find by id or by object

Posted: 19 Jan 2017 07:30 AM PST

It's usal to see codes where a model where search in a foreign key is realized passing the whole object. For instance, search user exercises:

Exercise.where(user: user)  

Another usual way to do that is:

Exercise.where(user_id: user.id)  

Checking in console log, both querys search by the user id, but there is a "most recommended" way between both? If yes, why: more elegant, performatic?

set Rails environment url for selenium remote

Posted: 19 Jan 2017 08:01 AM PST

I got selenium remote configured and running. I can access my development server (deployed with 'rails s') on '192.168.1.23:3000' from my computer using test methods like 'visit root_path' on capybara with minitest.

However, when I close my development server, I can't access my test server while testing, I just get a chrome error with page not found

test file:

require "test_helper"  feature "dashboard" do    scenario "test1", :js => true  do    #Rails.application.routes.default_url_options[:host]= 'http://192.168.1.23:3000'     visit root_path  end   

Note: activating line 4 gives me nil when running visit root_path

test_helper.rb

Capybara.configure do |config|     config.default_host = 'http://192.168.1.23:3000'    config.app_host   = 'http://192.168.1.23:3000'  end  

I've also tried test environment, test.rb

Rails.application.default_url_options = {:host => "http://192.168.1.23:3000" }  Rails.application.routes.default_url_options = {:host => "http://192.168.1.23:3000" }  

rails - kaminari pagination to non resource method

Posted: 19 Jan 2017 08:32 AM PST

kaminari is handeling pagination in my app, in example, if I want the missions index to be paginateable all I need is to add this code in routes.rb:

  concern :paginatable do      get '(page/:page)', :action => :index, :on => :collection, :as => ''    end      resources :missions, only: [:index, :create, :show, :destroy], :concerns => :paginatable do      post :done, on: :member    end  

and in the missions_controller.rb:

  def index      missions = Mission.all      if params[:page]        missions = missions.page(params[:page])      end      respond_with missions    end  

but what if I have in mission_controller.rb another method - missions for user:

  def user      missions = Mission.where(recipient_id: current_user.id)          if params[:page]        missions = missions.page(params[:page])      end      respond_with missions    end  

in routes.rb it is configured like this:

  get 'users_missions' => 'missions#user'  

how can I configure routes.rb to support pagination for this method?

activerecord filter out based on foreign table

Posted: 19 Jan 2017 07:11 AM PST

I am tryng to create a association where Vacancy has one or many schedules & possibly many matchings

Now I need to get the vacancies that are 2 weeks before starting and that have no matching with state approved

Vacancy.includes(:schedules)  .where(schedules: {start_date: Date.today..Date.today+14})  .order("schedules.start_date ASC")  .includes(:matchings).where.not(matchings: {state: "approved"})  

The first part works fine, I'm getting my vacancies and ordering them succesfully, although afterwards filtering out the ones that have a matching with approved does not work.

Syntax Error Ruby

Posted: 19 Jan 2017 06:40 AM PST

I have an rails application wherein i am scraping data from the internet. I have this snippet of code where it reports syntax errors thus preventing it from running.

I have tried to sort it out but unable to find out what is wrong. Where am i going wrong.

The snippet is shown below:

def reuters      ticker_sym = 'FB.O'      reuters_home_url = "http://in.reuters.com"      reuters_base_url = "http://in.reuters.com/finance/stocks/"      board_members =  Nokogiri::HTML(open(reuters_base_url + 'companyOfficers?symbol=' + ticker_sym.to_s ))      members = []      table = board_members.css('.column1 tbody.dataSmall').first      table_desc = board_members.css('.column1 tbody.dataSmall')[1]      table.css('tr').each_with_index do |row,index|        next if index == 0        members << {            name: row.css('td[1] h2 a').text.strip,            title: row.css('td[4]').text.strip,            position_held: row.css('td[3]').text.strip,            age: row.css('td[2]').text.strip,            member_link: URI.join(reuters_home_url,row.css('td[1] h2 a').attr("href")).to_s            table_desc.css('tr').each_with_index do |col,index2|              next if index2 == 0              members << {                  description: col.css('td[2]').text.strip              }            end          }      end    end  

Have attached a screenshot of my rails application error page shown below:

Rails error page

How do I add multiple recipients to an email in Rails4?

Posted: 19 Jan 2017 06:37 AM PST

I've been trying to add multiple recipients to a Mailer class by using the following code in Rails 4:

#/app/mailers/newsletter.rb  class Newsletter < ApplicationMailer      default to: Proc.new { Admin.pluck(:email) },            from: 'notification@example.com'      def sample_email      mail(subject: "Newsletter")    end    end    #/app/controllers/messages_controller.rb  class MessagesController < ApplicationController      def create      ...      if @message.save        Newsletter.sample_email.deliver_now        ...      else        ...      end    end    end  

The problem is that when I create a new message from the messages controller, I only recieve an email on one of the admin accounts (The first one) - My goal is to have the same email be sent to all the admins in my database.

I've obviously missed something, but I don't know what. Any help would be greatly appreciated.

getting query results attribute enclosed in \\(backslash) in rails

Posted: 19 Jan 2017 06:13 AM PST

User.last.childs

giving result as:

 [#<Child id: 3, company_id: 2, User_id: 8, var_number: \"1\", var_name: \"red_var\", created_at: \"2017-01-19 06:59:30\", updated_at: \"2017-01-19 09:15:54\"]  

Why result attributes showing inside \ \ like: \"1\", \"red_var\", \"2017-01-19 06:59:30\" etc.

I am using rails version 2.x

How to get normal value?  

Best option for DNS management

Posted: 19 Jan 2017 07:12 AM PST

From last few days traffic on website(https://www.fanspole.com/) is too high, so we are trying to optimise website. One thing I notice was DNS resolve time is too high..

@MacBook-Air ~ $ ping fanspole.com  PING fanspole.com (139.162.35.126): 56 data bytes  64 bytes from 139.162.35.126: icmp_seq=0 ttl=56 time=717.688 ms  64 bytes from 139.162.35.126: icmp_seq=1 ttl=56 time=606.560 ms  64 bytes from 139.162.35.126: icmp_seq=2 ttl=56 time=654.942 ms  64 bytes from 139.162.35.126: icmp_seq=3 ttl=56 time=677.301 ms  64 bytes from 139.162.35.126: icmp_seq=4 ttl=56 time=699.991 ms  Request timeout for icmp_seq 5  64 bytes from 139.162.35.126: icmp_seq=6 ttl=56 time=601.355 ms  64 bytes from 139.162.35.126: icmp_seq=7 ttl=56 time=660.974 ms  64 bytes from 139.162.35.126: icmp_seq=8 ttl=56 time=605.084 ms  --- fanspole.com ping statistics ---  10 packets transmitted, 8 packets received, 20.0% packet loss  round-trip min/avg/max/stddev = 601.355/652.987/717.688/42.087 ms  

we are using Linode DNS Manager as of now.. Can someone suggest better alternatives.

RubyCritic : How to remove FeatureEnvy?

Posted: 19 Jan 2017 07:36 AM PST

See Attachment

enter image description here

I have migration file that having 15 line of code. This 15 lines of code getting 3 smells.

  1. TooManyStatement
  2. UncommunicativeVariableName
  3. FeatureEnvy

I'm not able to understand How can i write this code to remove this errors?

So Please help me for this.

Rails get records after a certain ID

Posted: 19 Jan 2017 06:05 AM PST

In my app because records get created frequently I don't want to use a standard pagination mechanism because records wouldn't always be on the same page (records on page 2 today, might be on page 3 tomorrow). Instead what I want to do is request records after a certain ID.

So let's say I have 100 records in my posts table ranging from IDs 1-100, and I show 10 records at a time.

What I want to do is using params[:after] is request posts after that ID.

So if I have params[:after] == 10 I want to get records 11-21 (though 21 may not exist, so it's really 10 records in the table created_at ordered desc from the ID onwards.

In my controller I have something like:

if params[:after].present?    start_id = params[:after]    end_id = start_id+10    @posts = Post.where(:id => start_id..end_id).order('created_at desc').limit(10)  else    @posts = Post.order('created_at desc').limit(10)  end  

The problem I have is that the end_id will return the start_id+10 but in the DB the next 10 records IDs might not be that, so I'd end up with incorrect IDs coming back.

So ideally I need to know what the ID of the 10th post from this one is. How can I do this?

How to copy other column's value as default value for a new column in rails migration?

Posted: 19 Jan 2017 06:36 AM PST

I have a model with a column price. I need to add a new_column marked_price having value of price as it's default value. Can I write this in my migration, or what could be the best way to do this?

Something like:

class AddMarkedPriceToMenuItems < ActiveRecord::Migration    def change      add_column :menu_items, :marked_price, :decimal, :default => :price    end  end  

before_remove to abort removal crashes server when throwing exception

Posted: 19 Jan 2017 06:22 AM PST

I'm using Rails 5's Association Callbacks. I read in the documentation that if you want to abort an object removal from an association you have to throw an exception:

If a before_add callback throws an exception, the object does not get added to the collection. Similarly, if a before_remove callback throws an exception, the object does not get removed from the collection.

I'm doing exactly that but the server is crashing with a:

UncaughtThrowError (uncaught throw :abort)  

This is how my code looks like:

def can_remove_association(object)    return unless object.condition    errors[:base] << "Can't be removed."    throw(:abort)  end  

Any clue what's going on? The throw(:abort) is avoiding the object to be removed, but I get an ugly 500!

How to display images thumbnail

Posted: 19 Jan 2017 07:40 AM PST

In my rails app, I'm trying to implement a private gallery using carrierwave gem. Only owner of the gallery can visit gallery and sees images.

On the gallery show page these images should be displayed as thumbnails. I'm using reactjs for the view layer react_webpack_rails

For single image i can use send_file or send_data but these methods only open or download the image inside my browser and whats worse i cannot use them with ajax request.

Summary: In this situation, what is a correct and the most efficient way to pass images/data from rails controller to the client side?

how to save blob object in rails using paperclip. after editing a image i get blob object.how can i save it in my rails Db

Posted: 19 Jan 2017 06:34 AM PST

<%= f.hidden_field :document, :id=>"base64", :value=>"", :name=>"base64"  %>   <%= f.submit "SAVE",  :class=>"c-btn-green-light", :type=>"submit", :id=>"save_canvas", :onclick=>"dataObject()" %>  

Here, I am getting blob object after click save button

I want to send the blob object in a hidden field

Hook before all delyed job success callback to save successfully completed jobs

Posted: 19 Jan 2017 04:54 AM PST

Objective:

To save successfully completed jobs

Methods used

Have looked at this answer which tells how to save completed jobs and this answer which suggests to create a plugin which will be executed after one of lifecycle events.

Problem

There are following lifecycle events, and applicable arguments as present in code:

  :enqueue    => [:job],    :execute    => [:worker],    :loop       => [:worker],    :perform    => [:worker, :job],    :error      => [:worker, :job],    :failure    => [:worker, :job],    :invoke_job => [:job]  

I had expected there will be some event corresponding to success, I am not getting which one will be executed after job is successful.

Some Code

With the help of above tow answers, I have created this plugin to save completed job and put in config/initializers/save_completed_delayed_job.rb

module Delayed    module Plugins      class SaveCompletedDelayedJobPlugin < Plugin        callbacks do |lifecycle|          # see below for list of lifecycle events          lifecycle.after(:perform) do |job|            p "This should be ran after success so that I can save the job in different table"            CompletedDelayedJob.create({              priority: job.priority,              attempts: job.attempts,              handler: job.handler,              last_error: job.last_error,              run_at: job.run_at,              failed_at: job.failed_at,              completed_at: DateTime.now,              queue: job.queue              })            end        end      end    end  end    Delayed::Worker.plugins << Delayed::Plugins::SaveCompletedDelayedJobPlugin  

Why I need plugin

I can not use callback methods as I don't have dedicated job classed, I am using following code to queue job.

handle_asynchronously :deliver_delayed, :queue => 'my_q'  

How to leverage browser caching in Rails 4?

Posted: 19 Jan 2017 05:19 AM PST

I am using GTMetrix to see my site speed and it is showing me this (check below image).

How can I Leverage browser caching to speed up the site loading speed in Rails 4?

To defer parsing JS, I have already put

<%= javascript_include_tag 'application' %>  

before /html tag.

enter image description here

No comments:

Post a Comment