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 […]

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