Rails check_box_tag set checked with condition value

There are no ways to do it directly. But the check_box_tag implementation is trivial, you can monkey patch it or create own helper.

Original implementation:

  def check_box_tag(name, value = "1", checked = false, options = {})
    html_options = { "type" => "checkbox", "name" => name, "id" => sanitize_to_id(name), "value" => value }.update(options.stringify_keys)
    html_options["checked"] = "checked" if checked
    tag :input, html_options
  end

Which can be used in our view as following:

label
  - is_broker_selected = params[:search].present? && params[:search][:type].to_s.include?('Broker')
  div[class="icon-checkbox #{is_broker_selected == true ? 'grey' : ''}"]
  i.fa.fa-user
  = check_box_tag('search[type][]', 'Broker', is_broker_selected, class: 'search_type')
  | Broker

 

Reference: http://stackoverflow.com/questions/11796629/rails-check-box-tag-set-checked-with-default-value#_=_

 

Advertisements

Role of the Chief Technology Officer

Chief Technology Officer's Blog

Given the title of my Blog ‘Chief Technology Officer’s Blog’ – I thought it would be a good idea to briefly explore it’s namesake.

The role of the Chief Technology Officer (CTO) is one of the least defined and understood corporate executive roles (such as CEO, COO, CFO, CIO, etc).  The role has been gaining prominence in many organizations, as witnessed with the newly created position of Chief Technology Officer of the United States.  This can be attributed to the growing impact of technology on both organizations and society, and highlights an expansion of focus beyond Research and Development to broader Competitive Strategy.

According to Wikipedia

A chief technical officer or chief technology officer (abbreviated as CTO) is an executive position whose holder is focused on scientific and technical issues within an organization.  Essentially, a CTO is responsible for the transformation of capital – be it monetary, intellectual, or political – into technology in furtherance of the company’s objectives.

The…

View original post 268 more words

.gitignore is not working

Even if you haven’t tracked the files so far, git seems to be able to “know” about them even after you add them to .gitignore.


NOTE : First commit your current changes, or you will lose them.


Then run the following commands from the top folder of your git repo:

git rm -r --cached .
git add .
git commit -m "fixed untracked files"

Reference Link: http://stackoverflow.com/questions/11451535/gitignore-is-not-working

How to hire right person for the right job?

Here are few tips to hire right person for the right job. These tips are not my own tips. I have collected these tips from different sites.

  • Write better Job descriptions.
  • Focus on soft skills.
  • Check social media profiles. Specially for tech field, we can check Linkedin profile, gitbub profile etc.
  • Improve your interviews.
  •  Ask the right kinds of questions.
  • Look for someone with the commitment to their career.
  • Test for Excellent learning and Analytical skills.
  • Check compatibility.
  • Keep improve your hiring process.
  • Don’t forgot to hire Interns.

If you want to add more tips and other reference sites, feel free to add comment.

Reference Sites:

Set a default parameter value for a JavaScript function

First Solution

From ES6/ES2015, default parameters is in the language specification.

function read_file(file, delete_after = false) {
  // Code
}

just works.

Reference: Default Parameters – MDN

Default function parameters allow formal parameters to be initialized with default values if no value or undefined is passed.

Pre ES2015,

There are a lot of ways, but this is my preferred method – it lets you pass in anything you want, including false or null. (typeof null == "object")

function foo(a, b)
{
  a = typeof a !== 'undefined' ? a : 42;
  b = typeof b !== 'undefined' ? b : 'default_b';
  ...
}

Another Solution

To anyone interested in having there code work in Microsoft Edge, do not use defaults in function parameters.

function read_file(file, delete_after = false) {
    #code
}

In that example Edge will throw an error “Expecting ‘)'”

To get around this use

function read_file(file, delete_after) {
  if(delete_after == undefined)
  {
    delete_after = false;
  }
  #code
}

As of Aug 08 2016 this is still an issue

 

#Copied

Reference link: http://stackoverflow.com/questions/894860/set-a-default-parameter-value-for-a-javascript-function

Rails::Reply via Email::Using Postmark

nehasuwal

Sending emails from rails is an easy process. But sometimes we need to reply to the email itself that was sent by the app.

Postmark is the easiest and most reliable way to be sure your important transactional emails get to the inbox. Postmark allows you to send your application’s emails with high delivery rates, including bounce/spam processing and detailed statistics. In addition, Postmark can parse incoming emails which are forwarded back to your application.

The process of replying via email is known to be inbound.

How to implement Postmark in rails?

  1. Add add-on postmark in your Heroku or  sign up using https://account.postmarkapp.com ( If you add postmark as an add-on in Heroku you do not need to sign up additionally).
  2. Create your server by adding the name of the server.
  3. You can create a signature or even skip this step.
  4. Since we are implementing inbound process, we will need…

View original post 207 more words

Ruby : Public , Private, Protected simplified

My Daily Technical Notes [ Ruby, Rails, Gems, Server Ops]

class A
  privatedef pri
    'hey I am private of A'
  endprotecteddef prot
    'Hey I am protected of A'
  endendclass B < A
  def call_pri_of_a
    pri
  enddef call_prot_of_a
    prot
  endend

Now calling the accessors within B

 > b = B.new=> #<B:0x00000002b56ad8> 
 > b.call_pri_of_a
 => "hey I am private of A" 
 > b.call_prot_of_a
 => "Hey I am protected of A"

Up to here; there seem to be no difference

bb = B.new=> #<B:0x00000002b1a0b0>
def bb.access_private(child_of_B)
  child_of_B.pri
end
def bb.access_protected(child_of_B)
  child_of_B.prot
end

Now calling the accessor

> bb.access_private(b)
# => NoMethodError: private method `pri' called for #<B:0x00000002b56ad8>
> bb.access_protected(b)
# => "Hey I am protected of A"

View original post