Skip to main content

Posts

Showing posts from 2015

Facebook share url in rails

Facebook share url in rails?

https://www.facebook.com/dialog/feed?app_id=14563499550189 &display=popup&caption=An%20example%20caption&link=https%3A%2F%2Fdevelopers.facebook.com%2Fdocs%2&redirect_uri=https://developers.facebook.com/tools/explorer

Omniauth facebook email id not getting in rails?

Omniauth facebook email id not getting in rails?
Better way use the koala api get the email address Steps
1)gem "koala" 2)bundle install 3)Get the request.env['omniauth.auth'] 3)@graph = Koala::Facebook::API.new(request.env['omniauth.auth']['credentials']['token']) 4)user_email = @graph.get_object("me?fields=email")

Git branch and basic commands and rails3 to rails4

Rails 3 to Rails 4 Migrations


Ruby Version 2.2.2 Rails Version 4.2.3 Modification files
1)Gemfile Latest Gems related versions 2)Routes Change the match method with via get or post 3)Controllers New params creating and updating the data. i)params.require(:person).permit(:name, :age)
4)Models Active Record queries need to change i)Profile.where(“code is not null”) Profile.where.not(code: null) ii)Write the scopes in Models 5)Javascripts,stylesheets,images_paths Move the javascriptfiles and stylesheets to assets folder 6)Facebook,Linkedin,Twitter apis need to change Code changes Latest versions of the API



Git Related Commands
git branch List of branches for the git git chekout -b newbranchname(Like rails4_migration) Creating the new branch git checkout branchname(Like rails4_migration) Switching branche one branch to another branch git fetch It will pull the all branches in git

Gem::LoadError (Specified 'mysql2' for database adapter, but the gem is not loaded. Add `gem 'mysql2'` to your Gemfile (and ensure its version is at the minimum required by ActiveRecord).?

Gem::LoadError (Specified 'mysql2' for database adapter, but the gem is not loaded. Add `gem 'mysql2'` to your Gemfile (and ensure its version is at the minimum required by ActiveRecord).) In rails?


1)change the gemfile in mysql version
 gem 'mysql2'

2)Change to mysql2 version
 gem 'mysql2','0.3.20'

What are some GUI clients for Git? (Or) Update the code in git?

What are some GUI clients for Git?git gui - graphical commit tool, in Tcl/Tk, distributed with Git (usually in git-gui package)
git-cola - uses PyQt4
install all git gui tools sudo apt-get update && sudo apt-get install git-all Usage of git Gui 1)Project folder -> git gui 2)add the what are the files need to be commit 3)Add the git commit name 4)git push origin master

 git-cola also same as the git gui

Difference between rake db:migrate db:reset and db:schema:load in rails?

Difference between rake db:migrate db:reset and db:schema:load in rails?
db:migrateruns (single) migrations that have not run yet.
db:createcreates the database
db:dropdeletes the database
db:schema:loadcreates tables and columns within the (existing) database following schema.rb
db:setupdoes db:create, db:schema:load, db:seed
db:resetdoes db:drop, db:setup
Normally, db:migrate used after having made changes to the schema via new migration files after creating db i.e when db already exists.
db:schema:load is used when you setup a new instance of your app.

Creating Branches In git?

Creating Branches In git?

1)git checkout -b newbranchname
2)git add .
3)git commit -m "first commit on new branch"
4)git push origin newbranchname

Switching from one branch to another branch
git checkout branchname

Localchanges not requires
git stash

Conflict with git merges
1)git stash
2)git pull
3)git stash pop

git merge branchname

Git checkout with master
git chekout master

Checking the git branch

 git branch

git pull = git fetch + git merge Git update the only for particular commitsgit cherry-pick gitcommitidChange mode permissions for filechmod 600 filename

Usage of RestClient in Rails

Steps For Http post using rest clientCalling the Api calls in ruby on rails 1)gem install rest-client
2)We need to keep in whereever we want to use in rails controller
Example:
require 'rest-client'
class UsersController < ApplicationController
response = RestClient.post 'http://chinnaror.blogspot.in/test', :name => "koti",:email => "kotesh.raogaru@gmail.com"
data = JSON.parse response.body
p "data here......."
p data.inspect
p 999999999999999999999
end


In Chrome we can use the "Postman"  browser Software
Link:https://chrome.google.com/webstore/detail/postman/fhbjgbiflinjbdggehcddcbncdddomop?hl=en

In Mozilla We can use the "Restclient"  browser Software

Link:https://addons.mozilla.org/en-US/firefox/addon/restclient/

Install Rvm on ubuntu

sudo apt-get install libgdbm-dev libncurses5-dev automake libtool bison libffi-dev
curl -L https://get.rvm.io | bash -s stable
source ~/.rvm/scripts/rvm
rvm install 2.0.0-p645
rvm use 2.0.0-p645 --default
ruby -v
rvm gemset create rails3.2.8
rvm gemset use rails3.2.8
gem install rails -v 3.2.8

Ruby on rails Interview questions with answers for experience?

1)What is the difference between include and extend?
Ans:
i)Include makes the module methods are available instance of the class.
    1)Not available at the class level
    2)Available at the instance level
ii)extend makes module methods are available class itself.
    1)Not available at the class level
    2)Available at the instance level

  here is a big difference between include and extend in Ruby. Let me show you some code to explain it :
Exampl1:

module Printable
  def self.class_method_x
    p 'class_method_x'
  end

  def instance_method_y
    p 'instance_method_y'
  end
end



class ExtendDocument
  extend Printable
end



class IncludeDocument
  include Printable
end

First round, on the Printable module :

Printable.class_method_x
# => "class_method_x"



Printable.instance_method_y
# => NoMethodError: undefined method `instance_method_y' for Printable:Module

Second round, on ExtendDocument :

ExtendDocument.class_method_x
# => NoMethodError: undefined method `class_method_x…