All Blogs
Written by Kiprosh, team of passionate and disciplined craftsmen turning your ideas into reality.
Kiprosh
is now part of
LawLytics
Written by Kiprosh, team of passionate and disciplined craftsmen turning your ideas into reality.
Recently while working on one of our project there was an requirement of tracking count of records associated with has-many association. But also there was "is_hidden" flag set on some of the records which I do not suppose to count in counter as those were hidden records. So default counter_cache option of rails active-record was not appropriate in this case which automatically counts and caches the number of associated records and keeps cache updated. Refer following model code for this. class Order < ActiveRecord::Base belongs_to :customer, counter_cache: true end class Customer < ActiveRecord:
In our ember.js based project after getting latest code and running following commands: npm install && bower install npm start when I was starting app, it was failing randomly with following error. (FSEvents.framework) FSEventStreamStart: register_with_server: ERROR: f2d_register_rpc() => (null) (-21) events.js:85 throw er; // Unhandled 'error' event ^ Error: watch EMFILE at exports._errnoException (util.js:746:11) at FSEvent.FSWatcher._handle.onchange (fs.js:1161:26) npm ERR! Darwin 14.5.0 npm ERR! argv "node" "/usr/local/bin/npm" "start" .... To solve this issue I
Sometimes we need to show different text based on some count. Like for example: if box_count == 0 message = "No boxes present" elsif box_count == 1 message = "Only 1 box present" else message = "There are #{box_count} boxes" end You can refactor this to make use of i18n locales power. In en.yml you can do - en: boxes: message: zero: No boxes present one: Only 1 box present other: There are %{count} boxes And in view we can use: <%= t('boxes.message', count: 2) %>
In one of my project I would like to dump and export some information into a csv file. I have produced an easy script to do that. require 'csv' file = "#{Rails.root}/public/user_data.csv" products = Product.order(:first_name) headers = ["Product ID", "Name", "Price", "Description"] CSV.open(file, 'w', write_headers: true, headers: headers) do |writer| products.each do |product| writer << [product.id, product.name, product.price, product.description] end end Here is what the above snippet does: Require the CSV library, since we'll be manipulating
Hello @team, I found this article meaningful and thought of sharing. It's little lengthy but, worth reading. Ramayana, Mahabharata and Project Management… The Ramayana essentially highlights that team work is important for achieving the project objective. The team struggles at all times to win against all odds. They use out-of-box thinking to build bridges to Lanka. Lord Hanuman can be called as an expert in risk management. He takes great risks to support the mission. All the team members including the monkey brigade pledge their loyalty to Lord Ram. They have unflinching faith in their project leader. When one team
Recently in one of our project there was a requirement to send SMS notification to users and task was to perform this functionality as background job using delayed job service. I wrote following code for sending SMS notifications to user and it was working fine. Then I just did one liner change in my code to process send_sms method asynchronously using handle_asynchronously method of delayed job and thought it will work as expected. attr_reader :client, :sender, :recepient, :message def initialize(recipient_ph_number, message_details) @client = Twilio::REST::Client.new ACCOUNT_SID, AUTH_TOKEN @sender = TWILIO_PHONE_
I started learning React and developed a ToDo list application. Here is the github repo for this ToDo web application. This ToDo application has following functionality: add a new ToDo item inline edit an existing item delete an item drag & drop to sort or change the order This app is without any backend to keep things simple for now. I have used jQuery plugin jquery-editable for inline text editing of ToDo item. The mindset that we should not think jQuery way to implement UI in React helped me to implement or mix jQuery in correct way i.e. we
Most of the time, we use display: none property to hide the elements from out HTML page. Reference: http://www.w3schools.com/css/css_display_visibility.asp But this property might make you bang your head, if you are adding any event to the elements having this property. Yeah, recently we faced some strange issue in our ember-application. We have a image-upload feature in application. For that we have added a button "Add Image" and a file input. The file input we kept hidden and on click of the button "Add Image", we were triggering click
Few days back, we were facing problem establishing communication between a Webview control and a Titanium UI or vice versa. We were integrating Facebook authentication in our Titanium mobile app using Titanium Facebook mobule where we stumbled upon this issue. We wanted to trigger FB Auth Titanium module specific code on click of an HTML Login button tied with a jQuery click event. The FB auth module checks if Facebook mobile app is installed on the device and opens this mobile app for authentication otherwise it opens the browser window popup and redirects to Facebook site to authenticate. This is
Rails has provision to provide order of indexing on a column for better performance of like queries. The varchar_pattern_ops improves the performance of like queries by 4 times i.e 4x. For example, lets have this like query on name column (that has sequential index.) Select * from users where name like 'John%' We might have added a regular Rails index in migration for this name column as add_index :users, :name - This will generate a sequential index. The same can be made 4 times faster using btree index by adding xxx_pattern_ops options add_index