The precompile process is killed because it’s eating out your server’s RAM. You can confirm this by running top in another ssh session. To solve it, we have to create a swap file that will be used when RAM is full. First of all check if your system have any swap files sudo swapon -s […]

Trying rails server then this error occured:  /var/lib/gems/1.9.1/gems/execjs-2.2.1/lib/execjs/runtimes.rb:51:in `autodetect’: Could not find a JavaScript runtime. See https://github.com/sstephenson/execjs for a list of available runtimes. (ExecJS::RuntimeUnavailable) from /var/lib/gems/1.9.1/gems/execjs-2.2.1/lib/execjs.rb:5:in `<module:ExecJS>’ from /var/lib/gems/1.9.1/gems/execjs-2.2.1/lib/execjs.rb:4:in `<top (required)>’ from /var/lib/gems/1.9.1/gems/uglifier-2.5.3/lib/uglifier.rb:3:in `require’ from /var/lib/gems/1.9.1/gems/uglifier-2.5.3/lib/uglifier.rb:3:in `<top (required)>’ from /var/lib/gems/1.9.1/gems/bundler-1.7.0/lib/bundler/runtime.rb:76:in `require’ from /var/lib/gems/1.9.1/gems/bundler-1.7.0/lib/bundler/runtime.rb:76:in `block (2 levels) in require’ from /var/lib/gems/1.9.1/gems/bundler-1.7.0/lib/bundler/runtime.rb:72:in `each’ from /var/lib/gems/1.9.1/gems/bundler-1.7.0/lib/bundler/runtime.rb:72:in `block in […]

When you try to install rails by thsi command : sudo gem install rail, then this error keep occurring:  Building native extensions.  This could take a while…ERROR:  Error installing rails:    ERROR: Failed to build gem native extension.     /usr/bin/ruby1.9.1 -r ./siteconf20140817-14563-5arwq8.rb extconf.rb/usr/local/lib/site_ruby/1.9.1/rubygems/core_ext/kernel_require.rb:54:in `require’: cannot load such file — mkmf (LoadError)    from /usr/local/lib/site_ruby/1.9.1/rubygems/core_ext/kernel_require.rb:54:in `require’    from extconf.rb:1:in […]

Let’s say we have two model Photo and Album, and we like to attablish the many to many relationship between these two models. Here the whole process : 

  • Create Photo model like the following: 

class Photo < ActiveRecord::Base
# validate photo_id unique
validates_uniqueness_of :photo_id

# setup many to meny relationship with albums table
has_and_belongs_to_many :albums

end

Continue reading

You can use JQuery and Ajax to handle the pagination feature. However, there is a much easy way to have this feature working if you use Ruby on Rails. Here is how you got it work:  First install the Ruby plugin called  in Rails system will_paginate by the following command:  gem install will_paginate Then update your […]

I faced this error SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed when I try to implement the following: JSON.parse(open(“http://api……”).read). I found the solution to fix this SSL error right from Windows, here is how :  Download or click here to view into C:Ruby200-x64cacert.pem Go to your Computer -> Advanced Settings -> Environment Variables […]

The code : default_scope :order => ‘title’and this following error occurs : Support for calling #default_scope without a block is removed. For example instead of `default_scope where(color: ‘red’)`, please use `default_scope { where(color: ‘red’) }`. (Alternatively you can just redefine self.default_scope.) In order to fix this error, change your code to the following :  default_scope  { […]

Run rake db:seed and it generates the output:  rake db:seed –trace **Invoke db:seed (first_time)**Execute db:seed **Invoke db:abort_if_pending_migrations (first_time)**Invoke environment (first_time)**Execute environment **Invoke db:load_config (first_time)**Execute db:load_config **Execute db:abort_if_pending_migrations The reason for this problem is that the query is blocked by the validation of your model. Unfortunately, it won’t be displayed on the console output. In order […]

Source code :

class Product < ActiveRecord::Base

validates :title, :description, :image_url, :presence => true
validates :price, :numericality => {:greater_than_or_equal_to => 0.01}
validates :title, :uniqueness => true
validates :image_url, :format => {
:with => %r{.(gif|jpg|png)$}i,
:message => ‘must be a URL for GIF, JPG or PNG image.’
}
end

Continue reading

  • Setup Digital server, Nginx host rails, apache2 host PHPMYADMIN
  • Update gem:
    gem install rubygems-update
    update_rubygems
    gem update --system

    (if not work, try gem update `gem outdated | cut -d ' ' -f 1`)

  • Throw an exception manually :raise ....
  • Handle Photo and Album (kylehuynhphotography.com): click here
  • Clear the assets
    rake assets:clobber (remove /home/rails/tmp/cache/assets)
    rake assets:clean
  • Check the error log in kylehuynhphotography.com:
    cat /var/log/nginx/access.log
  • Validate string field is unique

validates :title, :uniqueness => true

  • Validating image url format as png, jpeg or gif

validates :image_url, :format => {
:with => %r{A.(gif|jpg|png)/z}i,
:message => ‘must be a URL for GIF, JPG or PNG image.’
}

Continue reading

First of all, run this command with oldname is the attribute that you like to change and newname is the attribute you like to replace rails g migration change_oldname_to_newname Look for the file ….. in ….. and modify like the following class change_oldname_to_newname <ActiveRecord::Migration def change rename_column :table_name,:old_column,:new_column endend Save the changes and update these […]

  • Start Rails server by$ rails server 
  • This error appears : 

=> Booting WEBrick=> Rails 4.1.4 application starting in development on http://0.0.0.0:3000
=> Run `rails server -h` for more startup options
=> Notice: server is listening on all interfaces (0.0.0.0). Consider using 127.0.0.1 (–binding option)
=> Ctrl-C to shutdown server
Exiting
C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/tzinfo-1.2.1/lib/tzinfo/data_source.rb:182:in `rescue in create_default_data_sou
rce’: No source of timezone data could be found. (TZInfo::DataSourceNotFound)
Please refer to http://tzinfo.github.io/datasourcenotfound for help resolving this error.
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/tzinfo-1.2.1/lib/tzinfo/data_source.rb:179:in `create_default_data_
source’
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/tzinfo-1.2.1/lib/tzinfo/data_source.rb:40:in `block in get’
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/tzinfo-1.2.1/lib/tzinfo/data_source.rb:39:in `synchronize’
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/tzinfo-1.2.1/lib/tzinfo/data_source.rb:39:in `get’
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/tzinfo-1.2.1/lib/tzinfo/timezone.rb:629:in `data_source’
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/tzinfo-1.2.1/lib/tzinfo/timezone.rb:92:in `get’
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/tzinfo-1.2.1/lib/tzinfo/timezone_proxy.rb:67:in `real_timezone’
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/tzinfo-1.2.1/lib/tzinfo/timezone_proxy.rb:30:in `period_for_utc’
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/tzinfo-1.2.1/lib/tzinfo/timezone.rb:549:in `current_period’

Here is solution: 

Continue reading

  • First of all, download factory image for your nexus device from here
  • Step 1: Download the ADB/Fastboot files and the USB drivers for Windows based PC first.
    • Extract the contents of the ADB/Faew folder called ‘google’ on your desktop. Extract and transfer the contents of the factory image inside this folder as well. The list of files will include a ZIP file containing the codename of your Android device, two files with “flash-all” names, and a bootloader image file. All the extracted contents of the factory image should be inside the same folder as the ADB and Fastboot file, otherwise you will get a file not found error.
    • Make sure to install the ADB drivers as well if you are running a Windows based PC.
  • Continue reading

    Here is how: To disallow comments in all posts and pages, do the following steps, this applies to new posts that you will publish from now on Settings >> Discussion >> uncheck “Allow people to post comments on new articles” But what about all of existing posts and page, here is how to disable comments from […]

    Sometimes you happen to change your remote server settings which you use for git. Then you try to pull and push with git and get the following error:  @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY! Someone could be eavesdropping on you right now […]

    Pick a directory to download the openssl files Download openssl wget https://www.openssl.org/source/openssl-1.0.1g.tar.gz Unzip the openssl package: tar -zxf openssl-1.0.1g.tar.gzcd openssl-1.0.1g./configmakemake testmake install Check openssl versio after installation : openssl version If it shows old version do the steps below. mv /usr/bin/openssl /root/ln -s /usr/local/ssl/bin/openssl /usr/bin/openssl Check the version again:  openssl version

    Open xampp/conf/extra/httpd-xampp.conf and look for and adding: <LocationMatch “^/(?i:(?:xampp|licenses|phpmyadmin|webalizer|server-status|server-info))”> Order deny,allow #Deny from all Allow from ::1 127.0.0.0/8 Allow from ::1 xxx.xxx.x.xxx (the computer’s IP address)    ErrorDocument 403 /error/HTTP_XAMPP_FORBIDDEN.html.var</LocationMatch> Finally, type the IP address of the computer with xampp in the address bar.   OR For testing purpose, you only have to turn off firewall by /etc/init.d/iptables […]