Saturday 25 February 2017

Make icon any type of for your web

http://www.flaticon.com/free-icon/circular-check-button_78016

Friday 24 February 2017

Click edit image icon upload image using javascript

 <img src="<%= asset_path( current_user.image ) %>" id="imgprvw" class="circle_img  img-circle" alt="Cinque Terre" width="150" height="136" style="border: 4px solid gray;margin-left:5% !important;">


    <img src="<%= asset_path('edit.png')%>" class="edit_pin" alt="Image" onclick = "$('#user-image').click();" width="40px"  >
   

<%= form_tag '/users/edit_profile_image', id: 'image_upload', :multipart => true do %>
<%= file_field_tag :avatar,name: "avatar",:id => "user-image" ,:onchange => "showimagepreview(this)" ,:class=>"img_file hide" %></td>
<% end %>


<script>
    function showimagepreview(input) {
      if (input.files && input.files[0]) {
      var filerdr = new FileReader();
      filerdr.onload = function(e) {
 
      $('#imgprvw').attr('src', e.target.result);
      }
      filerdr.readAsDataURL(input.files[0]);
      }
      $('#image_upload').submit();
    }
</script>

controller code

@user = current_user
     @user.image = params[:avatar] if params[:avatar].present?
     @user.save
     flash[:notice] = "Profile image has been updated."
     redirect_to :back

Login from Omniauth.

Step-1  Put gem into gemfile.
             gem 'omniauth-facebook'
              gem 'omniauth-twitter'
       gem "omniauth-google-oauth2"
             gem  'omniauth' 
  and after that run bundle command on your console.

Step-2  App->Config->initializer-> omniauth.rb. 
                  copy and paste few line below given.
          
        Rails.application.config.middleware.use OmniAuth::Builder do
provider :facebook, '10370967297316xxx' , '6703b75235b704e789aa9fbb649xxxx'

         or set environment variable
  provider :google_oauth2, ENV["GOOGLE_CLIENT_ID"], ENV["GOOGLE_CLIENT_SECRET"]
provider :twitter, ENV['TWITTER_KEY'], ENV['TWITTER_SECRET']
end

after you will change some thing in your config file you have to restart the server again.

Step-3 you have to added migration 

        rails g migration AddOmniautoToUsers
  
        open migration file copy and paste this code
        
        add_column :users, :provider, :string
  add_column :users, :uid, :string
  add_column :users, :name, :string
  in console  type command -> rake db:migrate

step -4 user model 

    def self.sign_in_from_omniauth(auth)
       user = where(provider: auth['provider'], uid: auth['uid']).first_or_initialize 
       user.email =  auth['info']['email']
       user.name = auth['info']['name']
       user.password = Devise.friendly_token[0,20]
       user.confirmed_at = Time.now
       user.save
      user
  end

step -5 User controller 

           def omniauth
auth=request.env["omniauth.auth"]
                session[:omniauth] = auth.except('extra')
                user = User.sign_in_from_omniauth(auth)
                sign_in user
                redirect_to root_url, notice: "SIGNED IN"
end


Step-6  in routes.rb
             get 'auth/:provider/callback', to: "users#omniauth"

Step 7 - put this is link in view 

<%= link_to  "/auth/facebook" do %>Facebook<% end %>
<%= link_to 'Twitter', '/auth/twitter' %>
<%= link_to 'Google+', '/auth/google' %>

Monday 13 February 2017

Sublime 2 Tab space


cd ~/.config/sublime-text-3/Packages/

sudo chown development:development User -R

Here development is the username of system like root, deploy

sudo nano ~/.config/sublime-text-3/Packages/User/Preferences.sublime-settings

add below

{
    "tab_size": 2
}

Revert last commit or second last and more....

 Git revert commit_id -m 1 this command willl revert last commit  Git revert commit_id -m 2 this command will revert second commit with same...