Posts

Showing posts with the label select

Searching on Select Box and Check Box || List

Searching on Select Box and Check Box Searching on List <input type="text" id="myInput" onkeyup="filterFunction()" placeholder="Search.." > <ul id="myulli">   <li><a href="#">abc</a></li>   <li><a href="#">xyz</a></li>  <li><a href="#">demo</a></li> <li><a href="#">testing</a></li> </ul> <script> function filterFunction(){    var input, filter, ul, li, a, i;    input = document.getElementById("myInput");    filter = input.value.toUpperCase();    div = document.getElementById("myulli");    a = div.getElementsByTagName("li");    console.log(a);    for (i = 0; i < a.length; i++) {        if (a[i].innerHTML.toUpperCase().indexOf(filter) > -1) {            a[i].style.display = "";        }

Difference Between select and collect

Difference Between select and collect Select & collect select return array of hash of all field into a table Example user.select(:id) // it will return all fields with id user.all.collect(&:id) // it will array of id's

Difference Between pluck and collect

Difference Between pluck and collect Pluck Pluck takes less time then collect because when we use collect we have to execute two queries for collecting record Example-  When have a user table and we have to collect all id's User.all.collect(&:id) // when we use collect we are running two query internally                                        first user.all and then we collect id's User.pluck(:id) // Here we are running only one query that's why it take less time Pluck also take more than one parameter at a time but collect can not Example- user.pluck(:id, :name) // it will return array of id and name user.collect(&:id , &:name) // it will give an error