Friday, 26 July 2019

 jQuery Geocoding and Places Autocomplete

<%= simple_form_for(@event_map) do |f| %>
  <%= hidden_field_tag :lat, nil, id: "lat" ,value: ""%>
  <%= hidden_field_tag :lng, nil, id: "lng",value: "" %>

  <%= f.error_notification %>
  <%= f.error_notification message: f.object.errors[:base].to_sentence if f.object.errors[:base].present? %>

  <div class="form-inputs">
    <%= f.input :title %>
    <%#= f.input :address %>
    <%= f.input :address, :label =>"Direction", :input_html => {:id=> 'autocomplete'}, :placeholder => 'Enter address' %>
    <%= f.input :street, :input_html =>{:id => 'route'} %>
    <%= f.input :street_number,  :input_html =>{:id => 'street_number'} %>
    <%= f.input :postal_code,  :input_html =>{:id => 'postal_code'} %>
    <%= f.input :city,  :input_html =>{:id => 'locality'} %>
    <%= f.input :state,  :input_html =>{:id => 'administrative_area_level_2'} %>
    <%= f.input :country, collection: EventMap.all,as: :select, :input_html =>{:id => 'country'} %>

    <%= f.input :start_date %>
    <%= f.input :end_date %>
  </div>

  <div class="form-actions">
    <%= f.button :submit %>
  </div>
<% end %>

<script src="http://maps.googleapis.com/maps/api/js?key=AIzaSyAvuPSxdugPS2FJQibo-i78wVZHWgmKemk&libraries=places"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/geocomplete/1.7.0/jquery.geocomplete.js"></script>

<script type="text/javascript">
$("#autocomplete").geocomplete()
          .bind("geocode:result", function(event, result){
            console.log("Data", result);
            $("#lat").val(result.geometry.viewport.ga.j)
            $("#lng").val(result.geometry.viewport.ga.l)

          });
</script>

Wednesday, 10 July 2019

GitHub/heroku clone push

How to clone project through Git Hub 
1. git clone https://github.com/dikshabittern/PostApplication.git
 ==> heroku git:clone -a appname (clone project through heroku)

    next, go to the PostApplication project
2. then, use this command=> bundle install
3. next, create a db use this cmd=> rails db:create
4. next, migrate a db => rails db:migrate

How to push code on GitHub and heroku 
 
 1. git remove -v (show Remote)
 2. git remote add origin repositary url
 3. git add . / git add file name
 4. git commit -m "message"
 5. git push origin master  / git push heroku master

create a new branch on github (git checkout -b "development")
change branch (git checkout branchname)
Merge all branch code in mail branch (git merge development)

whenever occur this error (Precompiling assets failed.) so use this code to debuging error (rake assets:precompile RAILS_ENV=production)
 



Tuesday, 9 July 2019

install PostgreSQL // error

  1. create a Project folder
  2. for ssh key generate use this command=> ssh-keygen
  3. add this key=> ssh-add
  4. Next, clone a project in Project folder use this cmd=>   
               git clone git@bitbucket.org:arvindkushwah9/igb_website.git
               cat /home/bittern/.ssh/id_rsa.pub
               cat ~/.ssh/id_rsa.pub
    5. run bundle install cmd
    6. gem install bundler
    7. When create a error for authentication  /var/lib/gems then use this cmd 
           sudo chmod -R 777 /var/lib/gems
    8. When create a error /usr/local/bin use this cmd=>
           sudo chmod -R 777 /usr/local/bin
    9. when occur a nokogiri error => gem install nokogiri

How to dump database with the help of this cmd =>
               pg_restore --verbose --clean --no-acl --no-owner -h localhost -U root -d mfindex_development latest.dump.7

1. ssh-keygen
2.ssh-add
   Permissions 0664 for '/home/bittern/.ssh/id_rsa' are too open.
   It is required that your private key files are NOT accessible by others.
   This private key will be ignored.
3. chmod 400 ~/.ssh/id_rsa
4. git clone git@github.com:ACATHONLLC/MFIndex.git

  error=>         You must use Bundler 2 or greater with this lockfile.  the use all these cmd=>
update Rubygems => gem update --system
update bundler=> gem install bundler
update gemfile.lock in your project => bundler update --bundler

5. then use this cmd bundle
6. rake db:create
7. How to dump database with the help of this cmd =>
               pg_restore --verbose --clean --no-acl --no-owner -h localhost -U root -d mfindex_development latest.dump.7




   How to install postgresql Database in rails
sudo sh -c "echo 'deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main' > /etc/apt/sources.list.d/pgdg.list"

wget --quiet -O - http://apt.postgresql.org/pub/repos/apt/ACCC4CF8.asc | sudo apt-key add -
sudo apt-get update
sudo apt-get install postgresql-common
sudo apt-get install postgresql-9.5 libpq-dev



sudo service postgresql restart

sudo -u postgres createuser root -s
sudo -u postgres psql
postgres=# \password  root 
 
10. then create a database=> rake db:create
11. psql -U root igb_dev < itgetsbrighter_net_29_05_2018.sql(after create a db)
13. when occur this error psql: FATAL:  Peer authentication failed for user "root" so follow these steps:-
     locate pg_hba.conf to open file

      sudo nano /etc/postgresql/9.5/main/pg_hba.conf(write file name)

      local   all             postgres                                md5

      local   all             root                                        md5
           and change all peer to md5
sudo service postgresql restart

To import database in our project

mysql -u root -p chumaround_dev11 < snaprent_17_05_2019.sql
psql -U root igb_website_02 < itgetsbrighter_net_29_05_2018.sql

14. next, run cmd rails s 
  when occur a error =>
(`validate_options': Missing required arguments: aws_access_key_id,aws_secret_access_key (ArgumentError))
15. Then create a application.yml in config folder and add.


config/Application.yml
      
 default:
   DATABASE_ADAPTER: postgresql
   DATABASE_USER: root
   DATABASE_PASSWORD: root
   DATABASE_NAME: igb_website_02
   DATABASE_HOST: localhost
   DOMAIN: localhost
   AWS_ACCESS_KEY_ID: AKIAIBP3UKKWLGXTJYHA
   AWS_SECRET_ACCESS_KEY: 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
   REGION: 'us-west-2'
   AWS_BUCKET_NAME: its-get-brighter-staging
   FACEBOOK_APP_ID: 4545544757845412155
   FACEBOOK_APP_SERCRET: 4454455451454544545454
   FACEBOOK_APP_VERSION: 'v2.8'

development:
   DATABASE_ADAPTER: postgresql
   DATABASE_USER: root
   DATABASE_PASSWORD: root
   DATABASE_NAME: igb_website_02
   DATABASE_HOST: localhost
   DOMAIN: localhost
   AWS_ACCESS_KEY_ID: AKIAIBP3UKKWLGXTJYHA
   AWS_SECRET_ACCESS_KEY: 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
   REGION: 'us-west-2'
   AWS_BUCKET_NAME: its-get-brighter-staging
   FACEBOOK_APP_ID: 4545544757845412155
   FACEBOOK_APP_SERCRET: 4454455451454544545454
   FACEBOOK_APP_VERSION: 'v2.8'
   TWITTER_CONSUMER_KEY: bXFWp9nwoKRZ4oiJZ4FtpMNhB
   TWITTER_CONSUMER_SECRET:
xBysm6YfAwpJOPhGuwcGv9GtpP0v0FbsscKs2ND7bzN14YPGEf


testing:
   DATABASE_ADAPTER: postgresql
   DATABASE_USER: root
   DATABASE_PASSWORD: root
   DATABASE_NAME: friend_booster_testing
   DATABASE_HOST: localhost
   DOMAIN: localhost
   AWS_ACCESS_KEY_ID: AKIAIBP3UKKWLGXTJYHA
   AWS_SECRET_ACCESS_KEY: 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
   REGION: 'us-west-2'
   AWS_BUCKET_NAME: its-get-brighter-staging
   FACEBOOK_APP_ID: 4545544757845412155
   FACEBOOK_APP_SERCRET: 4454455451454544545454
   FACEBOOK_APP_VERSION: 'v2.8'

production:
   DATABASE_ADAPTER: postgresql
   DATABASE_USER: root
   DATABASE_PASSWORD: root
   DATABASE_NAME: igb_website
   DATABASE_HOST: localhost
   DOMAIN: localhost
   AWS_ACCESS_KEY_ID: AKIAIBP3UKKWLGXTJYHA
   AWS_SECRET_ACCESS_KEY: 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
   REGION: 'us-west-2'
   AWS_BUCKET_NAME: its-get-brighter-staging
   FACEBOOK_APP_ID: 4545544757845412155
   FACEBOOK_APP_SERCRET: 4454455451454544545454
   FACEBOOK_APP_VERSION: 'v2.8'
   TWITTER_CONSUMER_KEY: bXFWp9nwoKRZ4oiJZ4FtpMNhB
   TWITTER_CONSUMER_SECRET:
xBysm6YfAwpJOPhGuwcGv9GtpP0v0FbsscKs2ND7bzN14YPGEf

# Staging
# production:
#   DATABASE_ADAPTER: postgresql
#   DATABASE_USER: igb_staging
#   DATABASE_PASSWORD: igb_staging
#   DATABASE_NAME: igb_development
#   DATABASE_HOST: igb-staging.c43bfw5renkv.us-west-2.rds.amazonaws.com
#   DOMAIN: localhost
#   AWS_ACCESS_KEY_ID: AKIAIBP3UKKWLGXTJYHA
#   AWS_SECRET_ACCESS_KEY: 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
#   REGION: 'us-west-2'
#   AWS_BUCKET_NAME: its-get-brighter-staging
#   FACEBOOK_APP_ID: 4545544757845412155
#   FACEBOOK_APP_SERCRET: 4454455451454544545454
#   FACEBOOK_APP_VERSION: 'v2.8'
#   GOOGLE_YOUTUBE_API_KEY: AIzaSyAOZpFNLMy0y4vs5ScWE0IaMq7nX-5OB7A
#   GOOGLE_YOUTUBE_CLIENT_ID:
781334102649-uks4t2v7p1cj2eintve3su7pjj5u8jrp.apps.googleusercontent.com
#   GOOGLE_YOUTUBE_CLIENT_SECRET: 9wcfYGe05Cht8rsiytU58-nK
#   TWITTER_CONSUMER_KEY: bXFWp9nwoKRZ4oiJZ4FtpMNhB
#   TWITTER_CONSUMER_SECRET:
xBysm6YfAwpJOPhGuwcGv9GtpP0v0FbsscKs2ND7bzN14YPGEf
#   IGB_FACEBOOK_UID: 10158476225585411
#   IGB_TWITTER_UID: 1022590795 
                 

                         

Friday, 5 July 2019

Freindship Request Delete

https://github.com/dikshabittern/PostApplication

Friendship Request/Rejected in Mini FB App


1)    create a friendship model 

                      rails g model Friendship sender_id:integr receiver_id:integer status_id:integer
                      Next, rails db:migrate
       show db table create friendship.rb
                      create_table :friendships do |t|
                             t.integer :sender_id
                             t.integer :receiver_id
                             t.integer :status_id, default: 1
                      t.timestamps
2)   create a index page in friendship folder(friendship/index.html.erb) and add..

             <div class="d-flex justify-content-center"><h1>List of Posts</h1></div><br>
                      <table class="table table-striped table-dark table-bordered">
              <thead>
          <tr>
      <th>Name</th>
      <th>Email</th>
      <th>Profile Image</th>
      <th>About</th>
      <th>Actions</th>
         </tr> 
             </thead>
3)    create a friendship controller 
              rails g controller Friendships

4)    How to use carrierwave in Project:-
             => gem 'carrierwave'
          then bundle 
      => Generating an Uploader
              rails generate uploader Avatar
      => this should give you a file in:
                         app/uploaders/avatar_uploader.rb
      => how you can customize your uploader. It should look something like this:
                      class AvatarUploader < CarrierWave::Uploader::Base
               storage :file
            end
            =>  Add a string column to the model you want to mount the uploader by creating a                      migration:
          rails g migration add_avatar_to_users avatar:string
          rails db:migrate
         =>  Open your model file and mount the uploader:
                    class User < ActiveRecord::Base
              mount_uploader :avatar, AvatarUploader
           end
        =>   In case you want to permit additional parameters (the lazy way™), you can do so                  using a simple before filter in your ApplicationController:
                      class ApplicationController < ActionController::Base 
                              # before_action :authenticate_user!
                              before_action :configure_permitted_parameters, if: :devise_controller?
    protected

    def configure_permitted_parameters

      devise_parameter_sanitizer.permit(:sign_up) do |user_params|
        user_params.permit({ roles: [] }, :email, :password, :password_confirmation,:first_name,:last_name)
      end

           devise_parameter_sanitizer.permit(:account_update) do |user_params|
                user_params.permit({ roles: [] }, :email, :password, :password_confirmation,:first_name,:last_name,:current_password)
      end

  end
end


https://github.com/dikshabittern/PostApplication

How To Use Mailer Function 


1=> Use the following command to generate a mailer as follows −
     rails g mailer UserMailer
2=> This will create a file user_mailer.rb in the app\mailer directory:-
     (app/mailer/user_mailer.rb)
3=> Let's create one method as follows :-

      def welcome_email(user)
        @user = user
        @url  = 'http://www.gmail.com'
        mail(to: @user.email, subject: 'Welcome to My Awesome Site')
      end
4=> Create a file called welcome_email.html.erb in app/views/user_mailer/. 
            <html>
                 <head>
                       <meta content = 'text/html; charset = UTF-8' http-equiv = 'Content-Type' />
                 </head>
   
            <body>
                <h1>Welcome to example.com, <%= @user.name %></h1>
                     <p>
                         You have successfully signed up to example.com,your username is: 
                          <%= @user.login %>.<br>
                     </p>
                     <p>
                         To login to the site, just follow this link: 
                         <%= @url %>.
                     </p>
                     <p>Thanks for joining and have a great day!</p>
           </body>
           </html>
5=>  add_email smtp setting:- config/environments/development

config.action_mailer.perform_deliveries = true config.action_mailer.raise_delivery_errors = true config.action_mailer.default_options = {from: 'localhost:3000'} config.action_mailer.delivery_method = :smtp config.action_mailer.smtp_settings = { address: 'smtp.gmail.com', port: 587, domain: 'localhost', user_name: 'testing.bittern@gmail.com', password: 'bittern12345', authentication: 'plain', enable_starttls_auto: true }

6=> send_email:-

UserMailer.welcome_email(User.first).deliver_later


Use Friendship_Mailer in Post Application Project 

1=> Use the following command to generate a mailer as follows −
            rails g mailer FriendshipMailer
2=> This will create a file friendship_mailer.rb in the app\mailer          directory:-
     (app/mailer/friendship_mailer.rb) and add this code 

        def send_request(friendship)
 @sender = User.find(friendship.sender_id)
 @receiver = User.find(friendship.receiver_id)
 mail(to: @receiver.email, subject: 'New Friend Request')
end

3=> Then, call and create a method in friendship.rb model after          create a send request method in friendship_controller.rb and        add this code in friendship.rb model.

       after_create :send_request_mail
       
       def send_request_mail
FriendshipMailer.send_request(self).deliver
       end
4=> Next, create a view send_request.html.rb in friendship_mailer        folder(friendship_mailer/send_request.html.erb)and add
       <h2>Hi <%= @receiver.name %>,</h2>

       <p><%= @sender.name %> send you a new friend request.</p>
5=> same as follow these steps for accepted and rejected view.
         
    Modify (app/mailer/friendship_mailer.rb) and add this code 

       def accept_request(friendship)
@sender = User.find(friendship.sender_id)
@receiver = User.find(friendship.receiver_id)
mail(to: @sender.email, subject: ' Request Accepted')
       end

       def reject_request(friendship)
@sender = User.find(friendship.sender_id)
@receiver = User.find(friendship.receiver_id)
mail(to: @sender.email, subject: ' Request Rejected')
       end
6=> create a accepted_request.html.erb and add this code..
       
      <h2>Hi <%= @sender.name %>,</h2>
      <p><%= @receiver.name %> has accepted your friend request.</p>

7=> create a rejected request.html.erb and add this code..
     <h2>Hi <%= @sender.name %>,</h2>
     <p><%= @receiver.name %> has Rejected your friend request.</p>


Wednesday, 3 July 2019

Like/Dislike/Reply


How to clone project from git hub repository

2. bundle install
3. rake db:create
4. rake db:migrate

How to create a Like/Dislike in Blog App

1. create a div in post show form(posts/show.html.erb) and add..

   <div id="post_likes">
      <%= render "likes/likes", likeable: @post %>
</div>
2. create a view page of likes in likes folder(likes/_likes.html.erb) and add.

<% if likeable.already_liked?(current_user) %>
<%= link_to 'Unlike', like_path(likeable.likes.where(user_id: current_user.id).first), method: :delete, remote: true %>
<% else %>
<%= link_to 'Like', likes_path(likeable_type: likeable.class.name, likeable_id: likeable.id), method: :post, remote: true %>
<% end %>
<small><%= likeable.likes.count %> likes</small>
3. Next, create a js file in likes folder(likes/create.js.erb) and add..

<% if @like.likeable.class.name == "Post" %>
$("#post_likes").html("<%= escape_javascript render 'likes/likes', likeable: @like.likeable %>");
<% elsif @like.likeable.class.name == "Comment" %>
$("#comment_<%= @like.likeable.id %>_likes").html("<%= escape_javascript render 'likes/likes', likeable: @like.likeable %>");
<% else %>
$("#reply_<%= @like.likeable.id %>_likes").html("<%= escape_javascript render 'likes/likes', likeable: @like.likeable %>");
<% end %>
4. Next, create a js file in likes folder(likes/destroy.js.erb) and add..
<% if @like.likeable.class.name == "Post" %>
$("#post_likes").html("<%= escape_javascript render 'likes/likes', likeable: @like.likeable %>");
<% elsif @like.likeable.class.name == "Comment" %>
$("#comment_<%= @like.likeable.id %>_likes").html("<%= escape_javascript render 'likes/likes', likeable: @like.likeable %>");
<% else %>
$("#reply_<%= @like.likeable.id %>_likes").html("<%= escape_javascript render 'likes/likes', likeable: @like.likeable %>");
<% end %>
5. Next, create a controller likes_controller.rb

class LikesController < ApplicationController
# before_action :find_post
before_action :find_like, only:[:destroy]
def create
if current_user.likes.where(likeable_id: params[:likeable_id], likeable_type: params[:likeable_type]).exists?
flash[:notice]= "you can't like more than once"
else
@like = current_user.likes.create(likeable_id: params[:likeable_id], likeable_type: params[:likeable_type])
end
end

def destroy
@like.destroy
end

def find_like
@like = Like.find(params[:id])
end

# private
# def find_post
# @post = Post.find(params[:post_id])
# end
end

6. Next, relationship establish in comment.rb model and add ..
has_many :likes, as: :likeable, dependent: :destroy
def already_liked?(user)
likes.where(user_id: user.id).exists?
End
7. Next, like.rb model and add..

class Like < ApplicationRecord
belongs_to :likeable, polymorphic: true
belongs_to :user
end
8. Next, post.rb model and add..
class Post < ApplicationRecord
has_many :comments, dependent: :destroy
has_many :likes, as: :likeable, dependent: :destroy
belongs_to :user
validates :title, presence: true, length: {minimum: 5}

def already_liked?(user)
likes.where(user_id: user.id).exists?
end
end

How to create a reply on comment
1. render a reply form in comment in comments folder  (comments/comment.html.erb)

<div id="replyForm">
<%= render 'replies/form', comment: comment %>
</div>
2. render a showReply page in comments folder (comments/comment.html.erb)

<div id="replyContainer">
<%= render 'comments/showreply', comment: comment %>
</div>
3. View of replies form (replies/_form.html.erb)

<%= form_with(model:[comment.post, comment, comment.replies.build], remote:true) do |f|%>

<%= f.hidden_field :user_id, value: current_user.id %>
<div class="form-group row d-flex justify-content-center">
<div class="col-md-10">
<%= f.text_field :body, class: "form-control", placeholder: "Reply" %>
</div>
<div class="col-md-2">
<%= f.submit "Send", class: "btn btn-primary" %>
</div>
</div>
<% end %>

4. View of showReply Page (comments/_showReply.html.erb)
<% comment.replies.each do |r| %>
<h5 class="card-title"><%= r.body %></h5>
<p class="card-text"><%= r.user.name %></p>
<p class="card-text"><small>
<%= time_ago_in_words(r.created_at) %></small></p>

<span id="reply_<%= r.id %>_likes">
<%= render "likes/likes", likeable: r %>
</span>

<% if current_user == r.user %>
<span> | <%= link_to 'Delete',[r.comment.post, r.comment, r], method: :delete, data: {confirm: 'Are you sure?'} %></span>
<% end %>
<hr>
<% end %>
5. create a js file in replies folder (replies.create.js.erb) and add..
$("#replyConatainer").html("<%= escape_javascript render 'comments/showreply', comment: @comment. %>");
$("#replyForm").html("<%= escape_javascript render 'replies/form', comment: @comment %>");
6. Modify comment.html.erb in comments folder and add..
<% if current_user == comment.user || current_user == comment.post.user %>
<span> | <%= link_to 'Delete',[comment.post, comment], method: :delete, data: {confirm: 'Are you sure?'} %>
</span>
<% end %>

7. Modify showReply.html.erb in comments folder and add..
<% if current_user == r.user || current_user == r.comment.user %>
<span> | <%= link_to 'Delete',[r.comment.post, r.comment, r], method: :delete, data: {confirm: 'Are you sure?'} %></span>
<% end %>

  Common Git Commands   Take clone of a repository git clone <remote-repository-url> ex: git clone  https://github.com/agricor/RegTech...