Friday, 29 April 2016

First app with print hello in react js simple and easy in 5 mins



Install node js


sudo su root
apt-get install nodejs


Install Global Packages


npm install babel -g
npm install webpack -g

create a new react app


mkdir reactApp
cd reactApp
npm init

// press only enter every time after inserting name as demo_app while ask to enter the input

sudo nano package.json

// replace code  with below code

======================================================

{
  "name": "demo_app",
  "version": "1.0.0",
  "description": "Lorem ipsum dolor sit amet",
  "main": "main.js",
  "scripts": {
      "start": "webpack-dev-server --hot"       
  },
  "repository": {
    "type": "git",
    "url": "git+ssh://git@github.com/npm/npm.git"
  },
  "author": "dev",
  "license": "ISC",
  "bugs": {
    "url": "https://github.com/npm/npm/issues"
  },
  "homepage": "https://github.com/npm/npm#readme",
  "private": true
}

======================================================

Add Dependencies and plugins
npm install react --save
npm install react-dom --save
npm install babel-core
npm install babel-loader
npm install babel-preset-react
npm install babel-preset-es2015

Create files
nano webpack.config.js
// paste below code======================================================

var config = {
   entry: './main.js',
  
   output: {
      path:'./',
      filename: 'index.js',
   },
  
   devServer: {
      inline: true,
      port: 7777
   },
  
   module: {
      loaders: [ {
         test: /\.jsx?$/,
         exclude: /node_modules/,
         loader: 'babel',
          
         query: {
            presets: ['es2015', 'react']
         }
      }]
   }
  
}

module.exports = config;

======================================================

nano index.html
// paste below code======================================================

<!DOCTYPE html>
<html lang = "en">

   <head>
      <meta charset = "UTF-8">
      <title>React App</title>
   </head>

   <body>
      <div id = "app"></div>
      <script src = "index.js"></script>
   </body>

</html>

=======================================================

nano App.jsx
// paste below code=======================================================

import React from 'react';

class App extends React.Component {
   render() {
      return (
         <div>
            Hello World!!!
         </div>
      );
   }
}

export default App;

=======================================================

nano main.js
// paste below code
=======================================================

import React from 'react';
import ReactDOM from 'react-dom';

import App from './App.jsx';

ReactDOM.render(<App />, document.getElementById('app'))

=======================================================

Run npm server
npm start

Open in browser

http://localhost:7777/

Sunday, 24 April 2016

Redirect back to current page after sign in, sign out

after_filter :store_location

    def store_location
      # store last url - this is needed for post-login redirect to whatever the user last visited.
      return unless request.get?
      if (request.path != "/users/sign_in" &&
          request.path != "/users/sign_up" &&
          request.path != "/users/password/new" &&
          request.path != "/users/password/edit" &&
          request.path != "/users/confirmation" &&
          request.path != "/users/sign_out" &&
          !request.xhr?) # don't store ajax calls
        session[:previous_url] = request.fullpath
      end
    end

    def after_sign_in_path_for(resource)
      session[:previous_url] || root_path 
    end

Tuesday, 19 April 2016

Form validation for email like user@example.com

 
 
<form id="regexpEmailForm" class="form-horizontal">
    <div class="form-group">
        <label class="col-xs-3 control-label">Email address</label>
        <div class="col-xs-7">
            <input type="text" class="form-control" name="email" />
        </div>
    </div>
</form>

<script>
$(document).ready(function() {
    $('#regexpEmailForm')
        .formValidation({
            framework: 'bootstrap',
            icon: {
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            fields: {
                email: {
                    validators: {
                        emailAddress: {
                            message: 'The value is not a valid email address'
                        },
                        regexp: {
                            regexp: '^[^@\\s]+@([^@\\s]+\\.)+[^@\\s]+$',
                            message: 'The value is not a valid email address'
                        }
                    }
                }
            }
        })
        .on('err.validator.fv', function(e, data) {
            // data.bv        --> The FormValidation.Base instance
            // data.field     --> The field name
            // data.element   --> The field element
            // data.validator --> The current validator name

            if (data.field === 'email') {
                // The email field is not valid
                data.element
                    .data('fv.messages')
                    // Hide all the messages
                    .find('.help-block[data-fv-for="' + data.field + '"]').hide()
                    // Show only message associated with current validator
                    .filter('[data-fv-validator="' + data.validator + '"]').show();
            }
        });
});
</script>

Tuesday, 12 April 2016

Delayed Job vs Resque vs Sidekiq

With delayed_job:
* Pros
– incredibly quick and easy to get rolling
– no addition to your “stack”; it can run just fine with ActiveRecord
– a fantastic choice for beginners or migrating code from the foreground to the background
* Cons
– Runs on ActiveRecord, so it will probably run slower than something that runs on Redis
– Makes it very easy to mix async and sync code in file, which, in my opinion, is a bad thing
– The “.delay” calls scattered across your codebase will make it difficult to reason about six months later

With Resque:
* Pros
– It runs on Redis, which is fast
– Great separation of background code with worker classes
– It has a fantastic web dashboard
– It makes it fairly easy to do background processing
* Cons
– More difficult to get running with than delayed_job
– Still isn’t the fastest!
– Doing prioritized, time-based jobs is not as easy as delayed_job

With Sidekiq:
* Pros
– Pretty darn fast and workers are lightweight
– You can port over code really easily from Resque
– Great separation of code
* Cons
– More difficult than delayed_job
– (this is the biggie) You must use thread-safe libraries and write thread-safe code



Version Latency Garbage created for 10,000 jobs Time to process 100,000 jobs Throughput
Sidekiq 4.0.0 10ms 151 MB 22 sec 4500 jobs/sec
Sidekiq 3.5.1 22ms 1257 MB 125 sec 800 jobs/sec
Resque 1.25.2 - - 420 sec 240 jobs/sec
DelayedJob 4.1.1 - - 465 sec 215 jobs/sec

Monday, 11 April 2016

some form validation css and js CDN

https://cdnjs.cloudflare.com/ajax/libs/formvalidation/0.6.1/css/formValidation.css
https://cdnjs.cloudflare.com/ajax/libs/formvalidation/0.6.1/css/formValidation.min.css
https://cdnjs.cloudflare.com/ajax/libs/formvalidation/0.6.1/js/formValidation.js
https://cdnjs.cloudflare.com/ajax/libs/formvalidation/0.6.1/js/formValidation.min.js
https://cdnjs.cloudflare.com/ajax/libs/formvalidation/0.6.1/js/framework/bootstrap.js
https://cdnjs.cloudflare.com/ajax/libs/formvalidation/0.6.1/js/framework/bootstrap.min.js
https://cdnjs.cloudflare.com/ajax/libs/formvalidation/0.6.1/js/framework/foundation.js
https://cdnjs.cloudflare.com/ajax/libs/formvalidation/0.6.1/js/framework/foundation.min.js
https://cdnjs.cloudflare.com/ajax/libs/formvalidation/0.6.1/js/framework/pure.js
https://cdnjs.cloudflare.com/ajax/libs/formvalidation/0.6.1/js/framework/pure.min.js
https://cdnjs.cloudflare.com/ajax/libs/formvalidation/0.6.1/js/framework/semantic.js
https://cdnjs.cloudflare.com/ajax/libs/formvalidation/0.6.1/js/framework/semantic.min.js

https://cdnjs.cloudflare.com/ajax/libs/formvalidation/0.6.1/js/framework/uikit.js
https://cdnjs.cloudflare.com/ajax/libs/formvalidation/0.6.1/js/framework/uikit.min.js
https://cdnjs.cloudflare.com/ajax/libs/formvalidation/0.6.1/js/language/ar_MA.js
https://cdnjs.cloudflare.com/ajax/libs/formvalidation/0.6.1/js/language/ar_MA.min.js
https://cdnjs.cloudflare.com/ajax/libs/formvalidation/0.6.1/js/language/be_FR.js
https://cdnjs.cloudflare.com/ajax/libs/formvalidation/0.6.1/js/language/be_FR.min.js
https://cdnjs.cloudflare.com/ajax/libs/formvalidation/0.6.1/js/language/be_NL.js
https://cdnjs.cloudflare.com/ajax/libs/formvalidation/0.6.1/js/language/be_NL.min.js
https://cdnjs.cloudflare.com/ajax/libs/formvalidation/0.6.1/js/language/bg_BG.js
https://cdnjs.cloudflare.com/ajax/libs/formvalidation/0.6.1/js/language/bg_BG.min.js
https://cdnjs.cloudflare.com/ajax/libs/formvalidation/0.6.1/js/language/cs_CZ.js

https://cdnjs.cloudflare.com/ajax/libs/formvalidation/0.6.1/js/language/cs_CZ.min.js

https://cdnjs.cloudflare.com/ajax/libs/formvalidation/0.6.1/js/language/da_DK.js
https://cdnjs.cloudflare.com/ajax/libs/formvalidation/0.6.1/js/language/da_DK.min.js
https://cdnjs.cloudflare.com/ajax/libs/formvalidation/0.6.1/js/language/de_DE.js
https://cdnjs.cloudflare.com/ajax/libs/formvalidation/0.6.1/js/language/de_DE.min.js
https://cdnjs.cloudflare.com/ajax/libs/formvalidation/0.6.1/js/language/en_US.js
https://cdnjs.cloudflare.com/ajax/libs/formvalidation/0.6.1/js/language/en_US.min.js
https://cdnjs.cloudflare.com/ajax/libs/formvalidation/0.6.1/js/language/es_CL.js

https://cdnjs.cloudflare.com/ajax/libs/formvalidation/0.6.1/js/language/es_CL.min.js
https://cdnjs.cloudflare.com/ajax/libs/formvalidation/0.6.1/js/language/es_ES.js
https://cdnjs.cloudflare.com/ajax/libs/formvalidation/0.6.1/js/language/es_ES.min.js
https://cdnjs.cloudflare.com/ajax/libs/formvalidation/0.6.1/js/language/fa_IR.js
https://cdnjs.cloudflare.com/ajax/libs/formvalidation/0.6.1/js/language/fa_IR.min.js
https://cdnjs.cloudflare.com/ajax/libs/formvalidation/0.6.1/js/language/fr_FR.js
https://cdnjs.cloudflare.com/ajax/libs/formvalidation/0.6.1/js/language/fr_FR.min.js
https://cdnjs.cloudflare.com/ajax/libs/formvalidation/0.6.1/js/language/gr_EL.js
https://cdnjs.cloudflare.com/ajax/libs/formvalidation/0.6.1/js/language/gr_EL.min.js
https://cdnjs.cloudflare.com/ajax/libs/formvalidation/0.6.1/js/language/he_IL.js
https://cdnjs.cloudflare.com/ajax/libs/formvalidation/0.6.1/js/language/he_IL.min.js
https://cdnjs.cloudflare.com/ajax/libs/formvalidation/0.6.1/js/language/hu_HU.js
https://cdnjs.cloudflare.com/ajax/libs/formvalidation/0.6.1/js/language/hu_HU.min.js

https://cdnjs.cloudflare.com/ajax/libs/formvalidation/0.6.1/js/language/id_ID.js

https://cdnjs.cloudflare.com/ajax/libs/formvalidation/0.6.1/js/language/id_ID.min.js
https://cdnjs.cloudflare.com/ajax/libs/formvalidation/0.6.1/js/language/it_IT.js
https://cdnjs.cloudflare.com/ajax/libs/formvalidation/0.6.1/js/language/it_IT.min.js
https://cdnjs.cloudflare.com/ajax/libs/formvalidation/0.6.1/js/language/ja_JP.js
https://cdnjs.cloudflare.com/ajax/libs/formvalidation/0.6.1/js/language/ja_JP.min.js
https://cdnjs.cloudflare.com/ajax/libs/formvalidation/0.6.1/js/language/nl_NL.js
https://cdnjs.cloudflare.com/ajax/libs/formvalidation/0.6.1/js/language/nl_NL.min.js
https://cdnjs.cloudflare.com/ajax/libs/formvalidation/0.6.1/js/language/no_NO.js
https://cdnjs.cloudflare.com/ajax/libs/formvalidation/0.6.1/js/language/no_NO.min.js
https://cdnjs.cloudflare.com/ajax/libs/formvalidation/0.6.1/js/language/pl_PL.js
https://cdnjs.cloudflare.com/ajax/libs/formvalidation/0.6.1/js/language/pl_PL.min.js
https://cdnjs.cloudflare.com/ajax/libs/formvalidation/0.6.1/js/language/pt_BR.js
https://cdnjs.cloudflare.com/ajax/libs/formvalidation/0.6.1/js/language/pt_BR.min.js
https://cdnjs.cloudflare.com/ajax/libs/formvalidation/0.6.1/js/language/pt_PT.js
https://cdnjs.cloudflare.com/ajax/libs/formvalidation/0.6.1/js/language/pt_PT.min.js
https://cdnjs.cloudflare.com/ajax/libs/formvalidation/0.6.1/js/language/ro_RO.js
https://cdnjs.cloudflare.com/ajax/libs/formvalidation/0.6.1/js/language/ro_RO.min.js
https://cdnjs.cloudflare.com/ajax/libs/formvalidation/0.6.1/js/language/ru_RU.js
https://cdnjs.cloudflare.com/ajax/libs/formvalidation/0.6.1/js/language/ru_RU.min.js
https://cdnjs.cloudflare.com/ajax/libs/formvalidation/0.6.1/js/language/sq_AL.js
https://cdnjs.cloudflare.com/ajax/libs/formvalidation/0.6.1/js/language/sq_AL.min.js
https://cdnjs.cloudflare.com/ajax/libs/formvalidation/0.6.1/js/language/sr_RS.js
https://cdnjs.cloudflare.com/ajax/libs/formvalidation/0.6.1/js/language/sr_RS.min.js
https://cdnjs.cloudflare.com/ajax/libs/formvalidation/0.6.1/js/language/sv_SE.js
https://cdnjs.cloudflare.com/ajax/libs/formvalidation/0.6.1/js/language/sv_SE.min.js
https://cdnjs.cloudflare.com/ajax/libs/formvalidation/0.6.1/js/language/th_TH.js
https://cdnjs.cloudflare.com/ajax/libs/formvalidation/0.6.1/js/language/th_TH.min.js
https://cdnjs.cloudflare.com/ajax/libs/formvalidation/0.6.1/js/language/tr_TR.js
https://cdnjs.cloudflare.com/ajax/libs/formvalidation/0.6.1/js/language/tr_TR.min.js
https://cdnjs.cloudflare.com/ajax/libs/formvalidation/0.6.1/js/language/ua_UA.js
https://cdnjs.cloudflare.com/ajax/libs/formvalidation/0.6.1/js/language/ua_UA.min.js
https://cdnjs.cloudflare.com/ajax/libs/formvalidation/0.6.1/js/language/vi_VN.js

https://cdnjs.cloudflare.com/ajax/libs/formvalidation/0.6.1/js/language/vi_VN.min.js

https://cdnjs.cloudflare.com/ajax/libs/formvalidation/0.6.1/js/language/zh_CN.js
https://cdnjs.cloudflare.com/ajax/libs/formvalidation/0.6.1/js/language/zh_CN.min.js
https://cdnjs.cloudflare.com/ajax/libs/formvalidation/0.6.1/js/language/zh_TW.js

https://cdnjs.cloudflare.com/ajax/libs/formvalidation/0.6.1/js/language/zh_TW.min.js

formvalidation css and js.


Add Bootstrap CSS and JS

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script> 


==============================================

Add Formvalidation CSS and JS

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/formvalidation/0.6.1/css/formValidation.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/formvalidation/0.6.1/js/formValidation.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/formvalidation/0.6.1/js/framework/bootstrap.min.js"></script>

Sunday, 10 April 2016

Hide qweb report option from print dropdown in odoo

create a report.xml file and paste below code.

<?xml version="1.0" encoding="utf-8"?>
<openerp>
    <data>
          <report id="sale.report_sale_order string="Quotation / Order" model="sale.order" report_type="qweb-pdf" file="sale.report_saleorder" name="sale.report_saleorder" menu="False"/>
    </data>
</openerp>

Steps for customize pdf of existing module.



1- Get the Inherit_id of the module which you want to customized the pdf from below process

Go To
Settings -> Technical -> Reports -> Reports
search the report which you want to customize
click on the report and view the information
click on search associated qweb views
click on the base dependent report
get the external id of that report



put this code in the report.xml


<report
    id="action_report_other_bit_invoice"
    model="sale.order"
    string="Other Bit Invoice"
    report_type="qweb-pdf"
    file="flex_website_product.report_otherbitinvoice"
    name="flex_website_product.report_otherbitinvoice"
/>

id: you can choos any id
model: the name of model you are going to inherit
string: give any name it will show in the dropdown
report_type: "qweb-pdf", indicates the type of report
file: your module name + template id
name: your module name + template id


create a new file template.xml

paste below code.

============================================

<template id="report_quotation_inherit_demo" inherit_id="sale.report_saleorder_document">
</template>

=============================================


paste your inherit id which you got from step 1

make changes from xpath. and check the full code in architecture tab.

Install Wkhtmltopdf on ubuntu 32/64 bit

Install Wkhtmltopdf

Go to the below url:
http://wkhtmltopdf.org/downloads.html

Go to the Stable section and click on 32-bit / 64- bit as per system architecture for linux.

open terminal.

unzip downloaded file.

follow below commands.

1- cd
2- sudo tar -vxf ~/Downloads/wkhtmltox-0.12.3_linux-generic-i386.tar.xz [32 bit]
or sudo tar -vxf ~/Downloads/wkhtmltox-0.12.3_linux-generic-amd64.tar.xz [64 bit]
3- sudo cp wkhtmltox/bin/wkhtmltopdf /usr/bin/
4- sudo chown root:root /usr/bin/wkhtmltopdf
5- sudo chmod +x /usr/bin/wkhtmltopdf

8 Insanely Useful ActiveAdmin Customizations

1. Adding a custom behavior to ActiveAdmin::BaseController:

Often times, you'll want to add a before_filter to something like your typical ApplicationController, but scoped to the ActiveAdmin engine. In this case, you can add custom behavior by following this pattern:
# config/initializers/active_admin_extensions.rb:
ActiveAdmin::BaseController.send(:include, ActiveAdmin::SiteRestriction)

# lib/active_admin/site_restriction.rb:
module ActiveAdmin
  module SiteRestriction
    extend ActiveSupport::Concern

    included do
      before_filter :restrict_to_own_site
    end

    private

    def restrict_to_own_site
      unless current_site == current_admin_user.site
        render_404
      end
    end
  end
end

2. Conditionally add a navigation menu item:

When you have multiple admin types, you may want to only show certain menu items to a specific type of admin user. You can conditionally show menu items:
# app/admin/resource.rb:
ActiveAdmin.register Resource do
  menu :parent => "Super Admin Only", :if => proc { current_admin_user.super_admin? }
end

3. To display an already uploaded image on the form:

ActiveAdmin uses Formtastic behind the scenes for forms. Persisting uploads between invalid form submissions can be accomplished via f.input :image_cache, :as => :hidden. However you may want to display the already uploaded image upon visiting the form for editing an existing item. You could use set one using a hint (f.input :image, :hint => (f.template.image_tag(f.object.image.url) if f.object.image?)), but this won't allow you to set any text as a hint. Instead, you could add some custom behavior to the Formtastic FileInput:
# app/admin/inputs/file_input.rb
class FileInput < Formtastic::Inputs::FileInput
  def to_html
    input_wrapping do
      label_html <<
        builder.file_field(method, input_html_options) <<
        image_preview_content
    end
  end

  private

  def image_preview_content
    image_preview? ? image_preview_html : ""
  end

  def image_preview?
    options[:image_preview] && @object.send(method).present?
  end

  def image_preview_html
    template.image_tag(@object.send(method).url, :class => "image-preview")
  end
end

# app/admin/my_class.rb
ActiveAdmin.register MyClass do

  form do |f|
    f.input :logo_image, :image_preview => true
  end
end

4. Scoping queries:

ActiveAdmin uses Inherited Resources behind the scenes. Inherited Resources uses the concept of resource and collection. ActiveAdmin uses a controller method called scoped_collection which we can override to add our own scope.
In your ActiveAdmin resource definition file:
# app/admin/my_class.rb
ActiveAdmin.register MyClass do 

  controller do
    def scoped_collection
      Post.for_site(current_site)
    end
  end
end
Similarly, you can override the resource method to customize how the singular resource is found.

5. Customizing the method by which a resource is found by the URL:

Often times we add a "slug" to a resource for prettier URLs. You can use your friendly URL parameters in the CMS as well:
# app/admin/page.rb
ActiveAdmin.register Page do

  controller do
    defaults :finder => :find_by_slug!
  end
end
I found that when a user submits the form while changing the slug value and the form is invalid, the next form submission will attempt to POST to the invalid slug. To fix this, I updated my model's to_param method from:
def to_param
  slug
end
To:
def to_param
  if invalid? && slug_changed?
    # return original slug value
    changes["slug"].first
  else
    slug
  end
end

6. Inserting arbitrary content into the form:

It can be handy to insert some explaining text, or even images, to within the Formtastic form itself. You'll need to insert the content into the form buffer:
Text:
form do |f|
  f.form_buffers.last << "<li>My Text</li>".html_safe
end
Image:
form do |f|
  f.form_buffers.last << f.template.image_tag('http://doge.com/image.png', :height => 350)
end

7. Dynamic Site Title:

It's possible you have multiple user types or sites that are managed via a single CMS. In this case, you may want to update the title displayed in the Navigation Menu.
# config/initializers/active_admin.rb
config.site_title = proc { "#{current_site.name} CMS" }

8. Manually defining sort order of top level navigation menu items:

It's easy to define the priority (sort order) of menu items when they belong to a parent, however if you are trying to set the sort order of top level parent items, it's a bit trickier.
# config/initializers/active_admin.rb
config.namespace :admin do |admin|
  admin.build_menu do |menu|
    menu.add :label => "First Item", :priority => 1
    menu.add :label => "Second Item", :priority => 2
    menu.add :label => "Third Item", :priority => 3
  end
end

Different Themes for Active Admin Rails

1- Active Admin Theme

Add in your gemfile

gem 'active_admin_theme'

Run Bundle

Add in active_admin.css.scss

$skinMainFirstColor: #A5A7AA!default;
$skinMainSecondColor: #0066CC!default;
$skinBorderWindowColor: #B8BABE!default;

@import "wigu/active_admin_theme";

2- Active Skin

Add in your gemfile

gem 'active_skin'

Run Bundle

Add in active_admin.css.scss

$skinActiveColor: #001cee;
$skinHeaderBck: #002744;
$panelHeaderBck: #002744;

@import "active_skin";

3- Active Admin Skin

Add in your gemfile

gem 'active-admin-skin'

Run Bundle

Add in active_admin.css.scss

$skinActiveColor: #eda600;
@import "active-admin-skin";

4- Active Admin Flat Skin


Add in your gemfile

gem 'active_admin_flat_skin'

Run Bundle

Add in active_admin.css.scss

$panelBorder: #babdc5;
$skinActiveColor: #e73c3c;
$bodyColor: rgba(236, 240, 241, 0.48);
$skinBlack: rgb(55, 71, 79);
$panelHeaderBck: $skinBlack;
$skinBlackLight: rgb(69, 90, 100);
$textGray: rgb(174, 179, 181);
$skinTextColor: #1e2a33;
$skinTextActiveColor: white;
$skinTextTable: #7f8c8d;
$skinHeaderBck: #1e2a33;

@import "active_admin_flat_skin";

Add in active_admin.js.coffee

//= require active_admin_flat_skin

5- Active Bootstrap Skin


Add in your gemfile

gem 'bootstrap-sass'
gem 'active_bootstrap_skin'

Run Bundle
 
rename your application.css to application.css.scss

Add in application.css.scss

@import "bootstrap-sprockets";
@import "bootstrap"

Add in application.js

//= require bootstrap-sprockets

Add in active_admin.css.scss

@import "active_bootstrap_skin";
Comment those lines in active_admin.css.scss [You have to comment active admin css otherwise bootstrap css will create conflict with active admin default css]

// @import "active_admin/mixins";
// @import "active_admin/base";

6-  Face of Active_Admin

Add in your gemfile

gem 'face_of_active_admin'

Run Bundle
 

Add in active_admin.css.scss

@import "active_bootstrap_skin";
change those lines in active_admin.css.scss

@import "active_admin/mixins";
@import "active_admin/base";

to

@import "face_of_active_admin/mixins";
@import "face_of_active_admin/base";

Add in active_admin.js.coffee

#= require face_of_active_admin/base

 
 
Note: In Active Admin Flat Skin there are some css issues, we will fix in next blog.  
 

Saturday, 9 April 2016

Action Mailer Configuration and Fix bugs in Rails

Hello All,

Now We are going to a short tutorial on SMTP configuration.

Development Environment:

Add Below Code in config/environments/development.rb



config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
  ActionMailer::Base.delivery_method = :smtp
  ActionMailer::Base.perform_deliveries = true
  ActionMailer::Base.raise_delivery_errors = true
  config.action_mailer.smtp_settings = {
      :address              => "smtp.gmail.com",
      :port                 => 587,
      :domain               => "gmail.com",
      :user_name            => "username@gmail.com",
      :password             => "password",
      :authentication       => :plain,
      :enable_starttls_auto => true
  }
  config.action_mailer.raise_delivery_errors = true



If You get below error so please follow instructions to solve the same.



Visit https://www.google.com/settings/security/lesssecureapps



change
Access for less secure apps

What does bundle exec rake mean?


You're running bundle exec on a program. The program's creators wrote it when certain versions of gems were available. The program Gemfile specifies the versions of the gems the creators decided to use. That is, the script was made to run correctly against these gem versions.
Your system-wide Gemfile may differ from this Gemfile. You may have newer or older gems with which this script doesn't play nice. This difference in versions can give you weird errors.
Bundle exec helps you avoid these errors. It executes the script using the gems specified in the script's Gemfile rather than the systemwide Gemfile. It executes the certain gem versions with the magic of shell aliases.
See more on the man page.
Here's an example Gemfile:
source 'http://rubygems.org'

gem 'rails', '2.8.3'
Here, bundle exec would execute the script using rails version 2.8.3 and not some other version you may have installed system-wide.


This comes up a lot when your gemfile.lock has different versions of the gems installed on your machine. You may get a warning after running rake (or rspec or others) such as:
You have already activated rake 10.3.1, but your Gemfile requires rake 10.1.0. Prepending "bundle exec" to your command may solve this.
Prepending bundle exec tells the bundler to execute this command regardless of the version differential. There isn't always an issue, however, you might run into problems.
Fortunately, there is a gem that solves this: rubygems-bundler.
$ gem install rubygems-bundler

$ $ gem regenerate_binstubs
Then try your rake, rspec, or whatever again.

Sunday, 3 April 2016

Difference between create and save in Ruby on Rails




Create is a class Method where as Save is an instance method, but both method belongs to Active Record::Base class.

If successfully validated, Create method creates an object (or multiple objects) and saves it to the database.The resulting object is returned whether the object was saved successfully to the database or not.

The parameters can either be a Hash or an Array of Hashes. These Hashes describe the attributes on the objects that are to be created

for ex- User.create(:firstname => “Jyoti Ranjan”)

From the above example, you can know that Create is a class method.
While in Save, If the model is new, a record gets created in the database, otherwise the existing record gets updated.

If the performed validation is true validations, then the save method will return true and save the content in the database. If any of them fail, the action is canceled and save returns false.

For ex- @user.save

From the above example, you can see that Save is an instance method.