Posts

Building native extensions. This could take a while... ERROR: Error installing mysql: ERROR: Failed to build gem native extension.

When we are getting problem with mysql like :-Building native extensions. This could take a while... ERROR: Error installing mysql: ERROR: Failed to build gem native extension.If we want to solve this problem so firstly we need to uninstall the mysql :-
Uninstall mysql :- https://www.linuxhelp.com/how-to-remove-mysql-package-completely-on-ubuntu-16-04/Then we need to install the mysql :-
https://www.digitalocean.com/community/tutorials/how-to-install-mysql-on-ubuntu-16-04
Then install the mysql gem :-
gem install mysql 
After that run the below command :-
sudo apt-get install libmysqlclient-dev

CREATE TABLE "schema_migrations" ("version" character varying(255) NOT NULL)

When we are getting problem with Postgres like :-: CREATE TABLE "schema_migrations" ("version" character varying(255) NOT NULL)
Solution :- 
Now you can follow the link below :- https://github.com/influitive/apartment/issues/17

RAILS: UPLOADING PHOTOS VIA AMAZON S3 AND PAPERCLIP (UPLOADING FILES TO S3 IN RUBY WITH PAPERCLIP)

Set up Ruby on Rails with Paperclip and S3 using AWS SDK
Uploading Files to S3 in Ruby with Paperclip Paperclip requires the following gems added to your Gemfile. If your paperclip version is 5.1.0 then we are using 'aws-sdk' version 2.3.# Gemfile
gem 'paperclip'
gem 'aws-sdk', '~> 2.3'
or our paperclip version is 4.1.0 then we need to use 'aws-sdk' version < 2  (note: add version less than 2.0 otherwise you will get paperclip error)gem 'paperclip'
gem 'aws-sdk', '< 2.0'


Run bundle install and restart the Rails server after modifying the Gemfile. Then run the command :-rails generate paperclip user image Define the file attribute in the Modelclass User < ActiveRecord::Base
    has_attached_file :image, styles: { medium: "300x300>", thumb: "100x100>" }, default_url: "/images/:style/missing.png"
      validates_attachment_content_type :image, content_type: /\Aimage\/.*\z/
end
Migration…

HOW TO CALL RAILS API FROM SIMPLE HTML PAGE.

Calling the rails API from simple HTML page. Step 1:  Create new form in the HTML page. index.html.erb<form action="javascript:void(0)">
  <input type="text" name="first_name" id="first_name">
  <select name="resident" id="resident">
    <option value="">Select</option>
    <option value="true">true</option>
    <option value="false">false</option>
  </select>
  <textarea type="textarea" name="notes" id="notes"></textarea>
  <input type="file" name="image" id="image">
  <button type="button" name="submit" id="form_submit_api">Send Data</button>
</form> 
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.js" integrity="sha256-DZAnKJ/6XZ9si04Hgrsxu/8s717jcIzLy3oi35EouyE=" crossorigi…

AWS::S3::ERRORS::ACCESSDENIED (ACCESS DENIED):

Image
Paperclip S3 AccessDenied Aws::S3::Errors::AccessDenied (Access Denied): Assuming you are using AWS’s IAM and you created a dedicated User for these uploads.If you get this error when trying to upload to S3, you need to assign this IAM User the “AmazonS3FullAccess” Policy.

GENERATE PDF FILE IN RAILS

Code Generating PDFs From HTML With Rails Using Wicked_pdf with Rails 5 Step 1 Install the required gemsgem 'wicked_pdf', '~> 1.1'  
gem 'wkhtmltopdf-binary'   
then generate the initializerrails g wicked_pdf               Step 2(optional) You need to register the pdf mime type. This is done in the initializer. This is required for older rails version only #config/initializers/mime_types.rbMime::Type.register "application/pdf", :pdf Step 3 Setup the controller to render pdf format. In this setup you have the options to configure so many item depends on you requirement. At the moment, only a few items need to be setup for me. #controllers/yours_controller.rbdef show
   .
   .
   .
   respond_to do |format|
    format.html
    format.pdf do
      render pdf: "Your_filename",
      template: "yours_controller/show.html.erb"
      layout: 'pdf'

    end
   end
end
Step 4 Create and setup the view part of the application First we create …

UNINITIALIZED CONSTANT PAPERCLIP::STORAGE::S3::AWS

Set up Ruby on Rails with Paperclip and S3 using AWS SDK Paperclip requires the following gems added to your Gemfile. If your paperclip version is 5.1.0 then we are using 'aws-sdk' version 2.3.gem 'paperclip'
gem 'aws-sdk', '~> 2.3'
or our paperclip version is 4.1.0 then we need to use 'aws-sdk' version < 2  (note: add version less than 2.0 otherwise you will get paperclip error)gem 'paperclip'
gem 'aws-sdk', '< 2.0'


Run bundle install and restart the Rails server after modifying the Gemfile.

WE CAN FOLLOW THE LINK BELOW :-

https://github.com/thoughtbot/paperclip/issues/2388
https://coderwall.com/p/vv1iwg/set-up-ruby-on-rails-with-paperclip-5-and-s3-using-aws-sdk-v2

DEPLOYING PROJECT USING CAPISTRANO (CAPISTRANO IN RAILS)

Image
We can Deploy project on Digital Ocean, AWS, Transip, Linode server ... using CapistranoWhat is Capistrano:- Capistrano is a remote server automation tool.

It supports the scripting and execution of arbitrary tasks, and includes a set of sane-default deployment workflows.

For that we have to follow simple steps :- How to Install Capistrano We can use Capistrano in RAILS 4, RAILS 5 as well as RAILS 2 and 3 . If we use RAILS 4 and 5 , then we can follow these steps :- 1.  Gemfile:- group :development do
             gem "capistrano"
             gem 'net-ssh'
             gem 'capistrano-bundler'
             gem 'capistrano-rails'
             gem 'capistrano-rvm'
             gem 'capistrano-sidekiq'
       end


2.   Run the bundle      cd /path/to/your/projectbundle 3.   Prepare your Project for Capistrano       capify .       This will create:       Capfile in the root directory of your Rails app       deploy.rb file in the config directo…

*** No MethodError Exception: undefined method 'split' for : "content-type": Symbol

When we upload the videos using carrier wave or paperclip then we mostly getting some content-type error like -*** No MethodError Exception: undefined method 'split' for : "content-type": Symbol
Then we have to check our RVM Version if version is  ruby-2.2.1

WE NEED TO CHANGE OUR RVM:-
WE NEED TO USE :-


 ruby-2.3.1

CARRIERWAVE - UPLOAD ANY MEDIA (AUDIO , VIDEO AND IMAGE ) FILE IN RAILS

Image
UPLOADING ANY MEDIA FILE WITH CARRIER-WAVE RAILS Multiple file uploads Add it to your Gemfile:      gem 'mime-types'
      gem 'mini_magick'
      gem 'rmagick'
      gem 'carrierwave', '~> 1.0'
      gem 'carrierwave-video'
      gem 'carrierwave-video-thumbnailer'
      gem 'carrierwave-ffmpeg'
Run
      bundle

Start off by generating an uploader:app/uploaders/vimeo_uploader.rb      rails generate uploader Vimeo Check out this file for some hints on how you can customize your uploader. It should look something like this:class VimeoUploader < CarrierWave::Uploader::Base
storage :file
end
If we want to upload video or image then we will have to use :-class VimeoUploader < CarrierWave::Uploader::Base
include CarrierWave::MiniMagick
      include CarrierWave::Video
      include CarrierWave::Video::Thumbnailer
      include CarrierWave::FFmpeg

      storage :file
     def store_dir
         "uploads/#{model.class.to_s.undersc…