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"

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

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