jeudi 28 octobre 2021

How to delete the domain and subdomain from session using devise

I am using rails device. I am trying to delete all domain and subdomain from session when the user logout but in my case after session.clear when i check the session still it shows the domain and subdomain name. is there any way i can delete domain and subdomain from the session after log out and destroy all sessions

session_store.rb

Rails.application.config.session_store :cookie_store, key: '_app_session'

session_controller.rb

def destroy
  signed_out = (Devise.sign_out_all_scopes ? sign_out : sign_out(resource_name))
  cookies.delete(:impersonate)
  cookies.delete("auth_token")
  session.clear
  respond_to_on_destroy

end

vendredi 22 octobre 2021

How we can implement Server-side Ag:grid for Tree-data in rails

My .haml file look like are as under:

here is we getting the data through getServerData() function

  async function getServerData(data) {
    const result = $.ajax({
      url: '/show_folder_documents/'+#{@client.id},
      method: 'GET',
      data: data,
      dataType: 'json'
    });
    return result;
  }

defining coldef...

  var columnDefs = [
    { field: 'group',hide:true},
    { field: 'folder_id',hide: true},
    { field: 'folder_name',hide: true}
  ];

defining gridoptions for aggrid...

   // let the grid know which columns and what data to use
  var gridOptions = {
    autoGroupColumnDef: {
      field: 'folder_name',
    },
    rowModelType: 'serverSide',
    serverSideStoreType: 'partial',
    treeData: true,
    columnDefs: columnDefs,
    rowSelection: 'multiple',
    animateRows: true,
    cacheBlockSize: 12,
    isServerSideGroup: function (dataItem) {
      // indicate if node is a group
      return dataItem.group;
    },
    getServerSideGroupKey: function (dataItem) {
      // specify which group key to use
      return dataItem.folder_id;
    },
  };

using this createServerSideDatasource() function we can pass the data to ag grid

  function createServerSideDatasource(data) {        
    function ServerSideDatasource(data) {
      this.data = data;
    }

    ServerSideDatasource.prototype.getRows = async function (params) {
      var mmm =  await getServerData(params.request);
      var doingInfinite = request.startRow != null && request.endRow != null;
      var result = doingInfinite
        ? {
            rowData: mmm['rows'],
            rowCount: mmm.length,
          }
        : { rowData: mmm };
      setTimeout(function () {
        params.success(result);
      }, 200);
    };

    return new ServerSideDatasource(data);
  }

so how can we put the things about mapping and how to rendering the tree data we got roots folder but the thing is we stuck to get the subs of them

How can remove some special character from string of array

def valid_sheet_names
   Company.find(@company_id).asset_types.pluck(:name).reject(&:nil?).map(&:downcase)
end

["hardware", "computer", "network", "mobile devices"]

this function return an array.i want to remove space, dot and underscore from string. but i don'y know how can i do this

jeudi 21 octobre 2021

Migration from Ruby 1.8.6 (my current release) RoR 2.0.2 (my current release) to the best of today

Hello, i want to do a Migration from Ruby 1.8.6 (my current release) RoR 2.0.2 (my current release) to the best of today. I want to know if you have any ideas on the steps to do this migration, and which version of Ruby and ROR do you recommend? and why?

mercredi 13 octobre 2021

Call Ajax if inputs are filled

I have two inputs, should call ajax when both are filled

<div class="col-md-6 col-xs-6"><%= form_input :first_name, wrapper: :default_form %></div>
<div class="col-md-6 col-xs-6"><%= form.input :last_name, wrapper: :default_form %></div>

I would like to verify if exists some users with first and last name equals

def verify_duplicate_user
 user = User.where('first_name LIKE ? AND last_name', "%#{params}%", "%#{params}%")
 true if user.size.positive?
end

How to use ajax in this case and open a modal if verify_duplicate_user returns some record

lundi 11 octobre 2021

bundle install on ruby on rails throwing mingw32 error

I'm very new on ruby and trying to install it for the first time on my machine my it's giving me these error i've already installed sqlite3 on my machine I don't know what is the cause please help

warning: Public keyring not found; have you run 'pacman-key --init'? error: mingw32: key "5F944B027F7FE2091985AA2EFA11531AA0AA7F57" is unknown error: keyring is not writable error: mingw64: key "5F944B027F7FE2091985AA2EFA11531AA0AA7F57" is unknown error: keyring is not writable error: ucrt64: key "5F944B027F7FE2091985AA2EFA11531AA0AA7F57" is unknown error: keyring is not writable error: clang64: key "5F944B027F7FE2091985AA2EFA11531AA0AA7F57" is unknown error: keyring is not writable error: msys: key "5F944B027F7FE2091985AA2EFA11531AA0AA7F57" is unknown error: keyring is not writable error: database 'mingw32' is not valid (invalid or corrupted database (PGP signature)) error: database 'mingw64' is not valid (invalid or corrupted database (PGP signature)) error: database 'ucrt64' is not valid (invalid or corrupted database (PGP signature)) error: database 'clang64' is not valid (invalid or corrupted database (PGP signature)) error: database 'msys' is not valid (invalid or corrupted database (PGP signature)) Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

image is attached for the reference enter image description here

vendredi 8 octobre 2021

Filter string to avoid complexity

I have string 'test1' and allowed values 'test1 test2 test3. Is a function to return string if it is in array of values to avoid complicated ifs or cases?

'test1'.function(['test1', 'test2', 'test3']) => test1
'test2'.function(['test1', 'test2', 'test3']) => test2
'test5'.function(['test1', 'test2', 'test3']) => nil

Regards

uninitialized constant ActiveStorage::Analyzer::ImageAnalyzer::MiniMagick

I'm getting this error on a Rails app on Heroku:

NameError: uninitialized constant ActiveStorage::Analyzer::ImageAnalyzer::MiniMagick
/app/vendor/bundle/ruby/3.0.0/gems/activestorage-6.1.3/lib/active_storage/analyzer/image_analyzer.rb:46:in `rescue in read_image'

It's happening in Sidekiq jobs generated from ActiveStorage::AnalyzeJob and seems to trigger whenever I try to upload an image to my AWS storage (the images are not reaching my bucket).

What is odd is I have a duplicate staging version of the app on Heroku that uses the same config and it does not trigger these errors (the images do reach my bucket from staging).

Both versions of the app are using the same gems and buildpacks.
Both versions have ImageMagick 6.9.10-23 and mini_magick 4.11.0 installed.
And both versions show the same error at the console if I reference the class mentioned, e.g.:

$ heroku run rails c -a my-staging-app
Running rails c on ⬢ my-staging-app... up, run.9122 (Free)
Loading staging environment (Rails 6.1.3)
irb(main):001:0*  ActiveStorage::Analyzer::ImageAnalyzer
=> ActiveStorage::Analyzer::ImageAnalyzer
irb(main):002:0>  ActiveStorage::Analyzer::ImageAnalyzer::MiniMagick
Traceback (most recent call last):
        1: from (irb):2:in `<main>'
NameError (uninitialized constant ActiveStorage::Analyzer::ImageAnalyzer::MiniMagick)
Did you mean?  MiniMime

But I have no idea why the staging app doesn't hit the error when uploading to AWS.

Does anyone know how I can fix the uninitialized constant? (Where does the referenced class need to come from?)

mercredi 6 octobre 2021

Rails won't start

Run somewhere else, I got correctly

>rails -v
Rails 6.1.4.1

un rails -v in project - I got an error. Something is going wrong. Ruby is on the path D:/Program Files/Ruby30-x64/bin/ruby.exe

D:/Program Files/Ruby30-x64/lib/ruby/gems/3.0.0/gems/railties-6.1.4.1/lib/rails/app_loader.rb:53:in `exec': No such file or directory - "D:/Program Files/Ruby30-x64/bin/ruby.exe" (Errno::ENOENT)
    from D:/Program Files/Ruby30-x64/lib/ruby/gems/3.0.0/gems/railties-6.1.4.1/lib/rails/app_loader.rb:53:in `block in exec_app'
    from D:/Program Files/Ruby30-x64/lib/ruby/gems/3.0.0/gems/railties-6.1.4.1/lib/rails/app_loader.rb:48:in `loop'
    from D:/Program Files/Ruby30-x64/lib/ruby/gems/3.0.0/gems/railties-6.1.4.1/lib/rails/app_loader.rb:48:in `exec_app'
    from D:/Program Files/Ruby30-x64/lib/ruby/gems/3.0.0/gems/railties-6.1.4.1/lib/rails/cli.rb:7:in `<top (required)>'
    from <internal:D:/Program Files/Ruby30-x64/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
    from <internal:D:/Program Files/Ruby30-x64/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
    from D:/Program Files/Ruby30-x64/lib/ruby/gems/3.0.0/gems/railties-6.1.4.1/exe/rails:10:in `<top (required)>'
    from d:/Program Files/Ruby30-x64/bin/rails:23:in `load'
    from d:/Program Files/Ruby30-x64/bin/rails:23:in `<main>'

>ruby -v
ruby 3.0.2p107 (2021-07-07 revision 0db68f0233) [x64-mingw32]

vendredi 1 octobre 2021

In ROR open link on a new tab, open another link through datatables using server side datatables

[].tap do |column|
      column << count
      links = []
      links << link_to("#{trainee.full_name}", profile_path(trainee.user.id)) 
      column << links 

This is traniees_datatables.rb file. when I click traniee name I want it to open in a new tab.

This work on index.slim file as

 td = link_to "#{trainee.full_name}", profile_path(trainee.user.id),target: "_blank", rel: "nofollow"

When I add target: "_blank", rel:"nofollow" in traniees_datatables.rb file shows an error.