Ignoring changed files from git commit

If you don’t want to show particular changed files in git commit Do follow steps

git update-index --skip-worktree FILENAME

git update-index --skip-worktree FILENAME

FILENAME like your file ex config/database.yml

If you use the second command (assume-unchanged), the files will revert after git resetcommand.

if You want to undo any of the above then run below command

git update-index --no-assume-unchanged FILENAME 

git commit revert back

  1. once you commit five files its stored into git object.\
  2. Then if you dont want revert back two files.
  3. Then do git reset –soft HEAD~ (it is for revert bak)
  4. git reset file_one
  5. git reset file_two
  6. then you can do checkout like
    git checkout file_one or file_two
  7. its same as previous file

Git conflict resolving

  1. git status (Shows all files that are in conflict as unmerged changed in working directory.)
  2. Resolve merge conflicts.
  3. git add <files> (conflict files)
  4. git commit -m “<Informative commit message>”

Use single attachment for video/image in paperclip

class Background < ActiveRecord::Base
 has_attached_file :background
 validates_attachment_presence :background
 validates_attachment_content_type :background,
 :content_type => ['video/mp4'],
 :message => "Sorry, right now we only support MP4 video",
 :if => :is_type_of_video?
 validates_attachment_content_type :background,
 :content_type => ['image/png', 'image/jpeg', 'image/jpg', 'image/gif'],
 :message => "Different error message",
 :if => :is_type_of_image?
 protected
 def is_type_of_video?
 background.content_type =~ %r(video)
 end
 def is_type_of_image?
 background.content_type =~ %r(image)
 end
end

what id difference b/w member route and collection route in rails

Let us take one example

resources :users do 
  member do
    get :preview
  end
end
resources :users do 
  collection do
    get :search
  end
end

A member route required id because it's act on member.
Collection route dont need id because its act as on collection of objects.
preview is an example of member route because it will display single object.
search is an example of collection route because it will display a collection of objects like index.

routes should like 

member          /users/1/preview   preview_user_path(user) 
collection      /users/search      search_users_url         
 
 

Clear the cache code in rails

1) addd this link to whenever you want

%li#clear_cache
%a{:href => “#{request.fullpath}#{request.fullpath.include?(‘?’) ? ‘&clear_cache=true’ : ‘?clear_cache=true’}”, :class => params[:clear_cache] == “true” ? “current” : “”}
%i.fa.fa-bars
%span Clear Cache
.clear

2) add before_filter :clear_all_cache in controller which controller you want

3) add below action in application controller

def clear_all_cache
binding.pry
if params[:clear_cache]
Rails.cache.clear
end
end