Posts

Showing posts from June, 2014

csv file upload progress bar in rails

I have added bootstrap progress bar when uploading csv file. Submit form using Ajax:-       <%= form_for @company, :url=>company_upload_path, :html => {multipart: true,:class=>"upload_form",:remote=>true,:id=>"new_company"} do |f| %>                           <%= file_field_tag "file",:class=>"form-control btn btn-default",:id=>"model_file" %>               <%= f.button 'Import', :class => 'submit  btn btn-primary import_button' %>               <% end %> Add progress-bar div when you want to show progress bar and give its initial width 0. <div class="progress" id = "import-campaign-bar">           <div  class="progress-bar progress-bar-success" style="width: 0%"></div> </div> def company_upload         # @company=Company.import_company(params[:company][:file], params[:tag],current_user,  

pdf in rails

Image
Create PDFs using HTML+CSS. Uses wkhtmltopdf on the back-end which renders HTML using Webkit. You need to install these gems mentioned below : gem install pdfkit gem install wkhtmltopdf-binary Than need to add this line into application.rb : config . middleware . use PDFKit :: Middleware , :print_media_type => true  Now In View you need to add content or whatever you wants to use : download_pdf.html.erb <H1>PDFKit works awesome</H1> This is you HTML data and going to be convert in pdf Than in the controller we need add this: class HomeController < ApplicationController def download_pdf html = render_to_string(:action => '../home/download_pdf', :layout => false) pdf = PDFKit.new(html) send_data(pdf.to_pdf) end end Than you need to add this link to download pdf or you can change as per your conditions : <p id="pdf_link"> <%= link_to "Download (PDF)", home_download_pdf_path(:form