Posts

Showing posts from 2018

RECURRING PAYMENT IN STRIPE, SUBSCRIPTION PAYMENT IN STRIPE RAILS

Image
Using Recurring Payment (Subscription Based)  RailsQuickly integrate Recurring payment into your Ruby on Rails-based site to provide your users with a streamlined, mobile-ready payment experience.Getting startedThe first step is adding the Stripe gem to your application’s Gemfile:gem 'stripe'

Then, run bundle install to install the gem.

https://dashboard.stripe.com/account/apikeys


Create config/initializers/stripe.rb:

Rails.configuration.stripe = {
  publishable_key: Rails.application.secrets.stripe_publishable_key,
  secret_key:      Rails.application.secrets.stripe_secret_key
}

Stripe.api_key = Rails.configuration.stripe[:secret_key]


We will use testing keys for the development environment. For production environment you need to configure with live keys to receive real payments.

Add these keys at config/secrets.yml:

development:
  stripe_publishable_key: pk_test_xxxxxxxxxxxxxxxxxxxxxxxx
  stripe_secret_key: sk_test_xxxxxxxxxxxxxxxxxxxxxxxx

production:
  stripe_publishable_key: ENV[…

STRIPE IN RAILS, CHECKOUT PAYMENT WITH STRIPE IN RAILS

Image
Using Checkout and Rails Quickly integrate Checkout into your Ruby on Rails-based site to provide your users with a streamlined, mobile-ready payment experience. Getting started The first step is adding the Stripe gem to your application’s Gemfile:gem 'stripe' Then, run bundle install to install the gem. Create config/initializers/stripe.rb:Rails.configuration.stripe = {
  publishable_key:  Rails.application.secrets.stripe_publishable_key,
  secret_key:          Rails.application.secrets.stripe_secret_key
}

Stripe.api_key = Rails.configuration.stripe[:secret_key]


We will use testing keys for the development environment. For production environment you need to configure with live keys to receive real payments. We can create the Stripe api keys from :- https://dashboard.stripe.com/account/apikeys Add these keys at config/secrets.yml:development:
  stripe_publishable_key: pk_test_xxxxxxxxxxxxxxxxxxxxxxxx
  stripe_secret_key: sk_test_xxxxxxxxxxxxxxxxxxxxxxxx

production:
  stripe_publishab…

CURL COMMAND ON RUBY ON RAILS

HOW TO USE CURL ON RUBY ON RAILS? LIKE THIS ONE curl -d 'params1[name]=name&params2[email]''http://mydomain.com/file.json' Just in case you don't know, it requires 'net/http' require 'net/http' uri = URI.parse("http://example.org")

RUN RAILS SERVER ON PORT 443

If we want to run the rails application in port 443 :- I have added the below line in /config/environments/production.rb: config.force_ssl =true Now I have tried the below attempts: Start rails on 3000 SSL=true rails s -e production -p 3000 It runs rails on https://project.com but 404 error on http://project.com Start rails on 443 and mentioned the same port in script:

AUTOCOMPLETE WITH AJAX IN RAILS

Image
Autocomplete with Ajax in rails index.html.erb page:-  <%= f.text_field :store_name, id: "store_shop" %>
controller :-class StaticController < ApplicationController
  def index; end

  def search
    if params['search'].size > 2
        result = search_shop(params['search'])
      found  = result.present? ?  result.map{|x| x["name"]} : result
      render :json => found
    else
      render :json => []
    end
  end
end
javascript :- // calling the third api from autocomplete
<script>
  $(function() {
    function log( message ) {
      $( "<div>" ).text( message ).prependTo( "#log" );
      $( "#log" ).scrollTop( 0 );
    }

    $( "#
store_shop" ).autocomplete({
      source: function( request, response ) {
       $.ajax({
          type: "get",
          url: "/static/brewery/",
          data: { search: request.term },
          dataType: "json",
          success: function…

psql: could not connect to server: No such file or directory Is the server running locally and accepting connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?

If we are getting error after creating database in postgres like this :-psql: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"? Then use following link :- https://stackoverflow.com/questions/42653690/psql-could-not-connect-to-server-no-such-file-or-directory-5432-errorsudo chmod 777 -R /var/run/postgresql/Then restart the postgres:-  sudo service postgresql restart orsudo systemctl start postgresql@9.6-main

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…