Friday, 12 November 2021

Active admin textbox/search functionality for selecting

 Add gem: 

gem 'activeadmin-searchable_select'

Import stylesheets and require javascripts:

// active_admin.scss
@import "active_admin/mixins";
@import "active_admin/base";

// active_admin.js
//= require active_admin/base
Add admin site in form field
f.input :account_id, as: :searchable_select, collection: AccountBlock::Account.all.map { |s| [s.profile.try(:name), s.id]}

Add ckeditor in active admin site

 


Gemfile: gem 'ckeditor'

active_admin.rb:  config.register_javascript "https://cdn.ckeditor.com/4.16.1/standard/ckeditor.js"

 admin_input:  f.input :contract, :input_html => { :class => "ckeditor" , :height => 400}

Friday, 1 October 2021

change Data base mysql to pg

 1. Create same database(database_name-thera_dev) both rails application in mysql and pg

2. Import sql file in mysql rails application.

3. then run this command for pg rails application .

"

pgloader mysql://root:root@127.0.0.1/DATABASE_NAME_SAME postgresql://root:root@127.0.0.1/DATABASE_NAME_SAME

"


4. then Export pg dupm file---this command run pg application

pg_dump -U root DATABASE_NAME_SAME > sql_file_name.sql


Thursday, 16 September 2021

Add Balance on stripe account

 token = Stripe::Token.create({

  card: {

    number: '4000000000000077',

    exp_month: 7,

    exp_year: 2022,

    cvc: '314',

  },

})


Stripe::Charge.create({

    'currency' => 'USD',

    'amount'   => 20000000,

    'source'   => token['id']

});

Wednesday, 8 September 2021

One form multiple time create

 <button type='button' onclick="addMore()">Add More (+)</button>

<%= form_with(model: article, id: "new_user") do |form| %>

  <% if article.errors.any? %>

    <div id="error_explanation">

      <h2><%= pluralize(article.errors.count, "error") %> prohibited this article from being saved:</h2>


      <ul>

        <% article.errors.each do |error| %>

          <li><%= error.full_message %></li>

        <% end %>

      </ul>

    </div>

  <% end %>


  <div class="field">

    <%= form.label :title %>

    <%= text_field_tag :title %>

  </div>

  <div id="dynamic-inputs"></div>

  <div class="actions">

    <%#= form.submit %>

  </div>

<% end %>

<button id='sendRequest' onclick="submiForm()">submit</button>


<script>

  function addMore(){

    $("#dynamic-inputs").append($("#new_user").html())

  }


  function submiForm() {

    let data = []

    $("[name='title']").each((i, item)=>

    {

    // debugger

      data.push({'title': item.value})

    })

    console.log({'quote_amounts': data})

    $.ajax({

        url: '/articles',

        data: {'quote_amounts': data},

        type: 'POST',

        success: function(data){

            // handle your success here

            console.log(data);

        }

    });

  }

</script>



For articles controller:

def create

    params[:quote_amounts].values.each_with_index do |ar,index|

      @article = Article.create(title: ar[:title], user_id: User.last.id)

    end

    # @article = Article.new(article_params)

    # @article.user_id = current_user.id

    # respond_to do |format|

    #   if @article.save

    #     # UserChannel.create_article(@article, current_user)

    #     format.html { redirect_to @article, notice: "Article was successfully created." }

    #     format.json { render :show, status: :created, location: @article }

    #   else

    #     format.html { render :new, status: :unprocessable_entity }

    #     format.json { render json: @article.errors, status: :unprocessable_entity }

    #   end

    # end

  end


Friday, 27 August 2021

Channel subscribe for jwt

 And connetc token for jwt

install smart web-socket client extention for chrome

2. Command for subscription

1. ws://0197-122-177-74-98.ngrok.io/cable?token=eyJhbGciOiJIUzUxMiJ9.eyJpZCI6MjIsImV4cCI6MTYzMDEzMjQzMn0.vogAtI5p2bA-AdbYGAa6ylrRJq5Y2s29d3AkmbXuLN7tkqHqMztUlzjglXXta5cchWa5BblFT-6KpfGrnAIirw


2. ws://localhost:3000/cable?token=eyJhbGciOiJIUzUxMiJ9.eyJpZCI6MjIsImV4cCI6MTYzMDEzMjQzMn0.vogAtI5p2bA-AdbYGAa6ylrRJq5Y2s29d3AkmbXuLN7tkqHqMztUlzjglXXta5cchWa5BblFT-6KpfGrnAIirw

{"command":"subscribe","identifier":"{\"channel\":\"ChatChannel\",\"id\":\"1\"}","data":"{

\"id\":\"1\"}"}

{"command":"subscribe","identifier":"{\"channel\":\"CallTrackerChannel\",\"chat_room_id\":\"22\"}","data":"{\"chat_room_id\":\"22\"}"}



Ngrok install and start rails server

 install ngrok for you system:

https://snapcraft.io/install/ngrok/ubuntu

-----------------------------------------

start ngrok server :

ngrok http 3000

and server restart on rails application rails s

https://dev.to/ianvaughan/ngrok-on-rails-315m

--------------------------------------------

./config/environments/development.rb

config.hosts << "0197-122-177-74-98.ngrok.io"

--------------------------------------------------------------

------------------------------------------------------------



Thursday, 24 June 2021

RVM is not a function, selecting rubies with 'rvm use …' will not work on Ubuntu

 

  1. Open terminal
  2. Select Terminal ->  Preferences (for top right site navbar) then click
  3. Select Unnamed
  4. Select tab: Command
  5. Check box 'Run command as a login shell' ---- first check box check
  6. Restart terminal

Sum of an Array

 Given an array [1,2,34,5,6,7,8,9], sum it up using a method:

def sum(array)
  return array.inject(:+)
end

Ruby install for new system and Rbenv

 


sudo apt install curl curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash - curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add - echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list sudo apt-get update sudo apt-get install git-core zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev software-properties-common libffi-dev nodejs yarn
sudo apt-get install libgdbm-dev libncurses5-dev automake libtool bison libffi-dev
gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB

Got this error: gpg: keyserver receive failed: Server indicated a failure

--------------------------------------------------------------------------------------------------

Then run for this command: 

curl -sSL https://get.rvm.io | bash -s stable
then got this error:

Downloading https://github.com/rvm/rvm/archive/1.29.12.tar.gz
Downloading https://github.com/rvm/rvm/releases/download/1.29.12/1.29.12.tar.gz.asc
gpg: Signature made Saturday 16 January 2021 12:16:22 AM IST
gpg:                using RSA key 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
gpg: Can't check signature: No public key
GPG signature verification failed for '/home/sadhna/.rvm/archives/rvm-1.29.12.tgz' - 'https://github.com/rvm/rvm/releases/download/1.29.12/1.29.12.tar.gz.asc'! Try to install GPG v2 and then fetch the public key:

    gpg2 --keyserver hkp://pool.sks-keyservers.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB

or if it fails:

    command curl -sSL https://rvm.io/mpapis.asc | gpg2 --import -
    command curl -sSL https://rvm.io/pkuczynski.asc | gpg2 --import -

In case of further problems with validation please refer to https://rvm.io/rvm/security
-----------------------------------------------------------------------------------------------------------

Follow this link: https://rvm.io/rvm/security

Then run: gpg --keyserver hkp://pool.sks-keyservers.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB

Then run command: curl -sSL https://get.rvm.io | bash -s stable

Then run tow command:

command1 curl -sSL https://rvm.io/mpapis.asc | gpg2 --import -

command2 curl -sSL https://rvm.io/pkuczynski.asc | gpg2 --import -

---------------------------------------------------------------------------------------------------------------

Then rvm install: rvm install 2.6.7

So got this error: 

Error running 'requirements_debian_update_system ruby-2.6.7',

please read /home/sadhna/.rvm/log/1624518537_ruby-2.6.5/update_system.log

Requirements installation failed with status: 100.

---------------------------------------------------------------------------------------

Solve this error: 

Run this command: rvm autolibs disable

Then run rvm install : rvm install 2.6.7



Solve

  1. source ~/.rvm/scripts/rvm
  2. rvm requirements


Finally ruby install 

-------------------------------------------------------------------------

Install ruby on ubuntu 22

Ubuntu 22

https://github.com/rvm/ubuntu_rvm/issues/67
$ cd /usr/local/src/
$ sudo wget https://www.openssl.org/source/openssl-1.1.1n.tar.gz
$ sudo tar -xf openssl-1.1.1n.tar.gz
$ cd openssl-1.1.1n
$ sudo ./config --prefix=/usr/local/ssl --openssldir=/usr/local/ssl shared zlib
$ sudo make
$ sudo make install
$ sudo rmdir certs
$ sudo ln -sf /etc/ssl/certs/ certs
rvm install 3.1.2 --with-openssl-dir=/usr/local/ssl
Install Rbenv: https://www.swhosting.com/en/comunidad/manual/how-to-install-ruby-on-rails-with-rbenv-on-ubuntu-2204

















 

Wednesday, 23 June 2021

Create coverage file

 https://github.com/simplecov-ruby/simplecov

==================================

Add gem file:

group :development, :test do

  # Call 'byebug' anywhere in the code to stop execution and get a debugger console

  gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]

  gem 'simplecov', require: false

end

then install bundle install

==================================

Add a spec/spec_helper.rb

require 'simplecov'

RSpec.configure do |config|

  SimpleCov.start 'rails'

end

==================================

Thursday, 4 March 2021

Password is not required

For User Model 


validates :password, :presence => true, :on => :create

before_save :password_required?

before_update :password_required?


def password_required?

    if self.password.present?

      true

    else

      false

    end

  end

Wednesday, 6 January 2021

Mysql dum on server

mysqldump -h HOST_NAME -u USER_NAME -p DATABASE_NAME > fittac_dev_07_01_2021.sql

Then Enter Password.