Posts

Showing posts from May, 2019

how to make separate routes for different user in rails

how to make separate routes for different user in rails  Make another routes file in your config folder           config/routes/admin.rb   //i made new file routes/admin.rb inside config folder Now inside your config/routes.rb file paste this           class ActionDispatch::Routing::Mapper             def draw(routes_name)              instance_eval(File.read(Rails.root.join("config/routes/#{routes_name}.rb")))             end           end        // paste this code above this Rails.application.routes.draw line now side your main route file(config/routes.rb) make new routes for admin file like draw :admin Now config/routes.rb will be look like this Rails.application.routes.draw do   draw :admin end Now you can make routes for admin or admin dashboard separately inside your config/routes/admin.rb file resources :admin

install wine in ubuntu

Step 1 – Setup PPA sudo dpkg --add-architecture i386 wget -qO - https://dl.winehq.org/wine-builds/winehq.key | sudo apt-key add - ###  Ubuntu 18.10  sudo apt-add-repository 'deb https://dl.winehq.org/wine-builds/ubuntu/ cosmic main' ###  Ubuntu 18.04  sudo apt-add-repository 'deb https://dl.winehq.org/wine-builds/ubuntu/ bionic main' ###  Ubuntu 16.04  sudo apt-add-repository 'deb https://dl.winehq.org/wine-builds/ubuntu/ xenial main' Step 2 – Install Wine on Ubuntu sudo apt-get update sudo apt-get install --install-recommends winehq-stable sudo apt-get install aptitude sudo aptitude install winehq-stable Step 3 – Check Wine Version wine --version wine-4.0 How to Use Wine (Optional)? wine full_file_full_specified_name.exe

ActiveRecord::Base.connection.execute, robust record execute in rails

ActiveRecord::Base.transaction do          ActiveRecord::Base.connection.execute("UPDATE deposits SET amount = #{params[:adjust_amount].to_f} WHERE type = '#{@deposit.type}' AND id = #{@deposit.id} AND currency_id = '#{@deposit.currency_id}'").as_json if params[:adjust_amount].present?          ## update comment          if params[:mt5_history_id].present?            mt5_withdraw_history = Mt5History.find_by_id(params[:mt5_history_id])            mt5_withdraw_history.update(comment: params[:comment])          end        end This do loop will run until all parameter will execute if any record updatation is failed due to some reason all previous record update will be rollback!   

Wicked-PDF not showing images, 'wicked_pdf_image_tag' undefined

Wicked-PDF not showing images, 'wicked_pdf_image_tag' undefined <div>   <%= wicked_pdf_image_tag 'logo.jpg' %> </div> def save   pdf = WickedPdf.new.pdf_from_string(                         render_to_string(                           template: 'example/pdf_view.pdf.erb',                           layout: 'layouts/application.pdf.erb'))   send_data(pdf,             filename: 'file_name.pdf',             type: 'application/pdf',             disposition: 'attachment')  end 

Download pdf by ajax or javascript or angular js

Click on button for generate pdf  $("#print_selected_label").on("click", function(){    data = []    $("input:checkbox.print_label:checked").each(function(){      data.push($(this).attr("id"));    });   //getting all information of checked checkbox    if(data.length > 0){    // if data is not null       In angular js controller         // var redirect_new = "/admin/v2/orders/print_multiple_label.pdf?" + jQuery.param(data);        // var pdf = window.open(redirect_new, 'Map PDF', '');      By Creating a link by javascript       // var mydiv = document.getElementById("download_pdf");      // var aTag = document.createElement('a');      // var link = " admin/v2/orders/print_multiple_label.pdf?id="+data ;      // aTag.setAttribute('href',link);      // aTag.innerHTML = "link text";      // mydiv.appendChild(aTag);      // aTag.click(); By making http request