Skip to main content

Posts

How to implement dependent dropdowns in Rails 4 with an unobtrusive jQuery script ?

How to implement dependent dropdowns in Rails 4 with an unobtrusive jQuery script ? class SpecializationType < ActiveRecord::Base   # FIELDS   # RELATIONS   has_many :specializations   # TRIGGERS   # VALIDATIONS   validates :name, :presence => true   validates :description, :presence => true   # SCOPES   # OTHER   def to_s     name   end end class Specialization < ActiveRecord::Base   # FIELDS   # RELATIONS   belongs_to :specialization_type   has_and_belongs_to_many :users   # TRIGGERS   # VALIDATIONS   validates :name, :presence => true   validates :description, :presence => true   validates :specialization_type, :presence => true   # SCOPES   # OTHER   def to_s     name   end end in views <%= form_tag users_path, {:method => :get, :class => "users_search_form"} do %>       <...

Mysql DataTypes

Mysql DataTypes ?     BOOLEAN - A boolean value either true, false or null.     CHAR(size) or CHARACTER(size) - A string of fixed length. The maximum size of a CHAR string is 1 billion characters.     VARCHAR(size), LONGVARCHAR(size), CHARACTER VARYING(size), LONG CHARACTER VARYING(size), TEXT(size) or STRING(size) - A string of variable length. The size constraint of these string types do not have to be given and defaults to the maximum possible size of strings that the database is able to store. The maximum size of these string types is 1 billion characters.     CLOB - A string of variable length without a size constraint. The maximum size of a CLOB object is 1 billion characters.     TINYINT - An 8-bit signed integer value. The range of TINYINT is -128 to 127.     SMALLINT - A 16-bit signed integer value. The range of SMALLINT is -32768 to 32767.     INTEGER or INT - A 32-bit si...

Facebook share url in rails

 Facebook share url in rails ? https://www.facebook.com/sharer/sharer.php?s=100&p[title]=thisismytitle&p[summary]=thisismysummary&p[url]=http://www.google.com&&p[images][0]=www.mysit/imag.jpg%27,%20%27Facebook%27,%20%27width=626,height=436,toolbar=0,status=0

Creating Your First Gem In Ruby on Rails

Creating Your First Gem In Ruby on Rails ? RubyGems The RubyGems package manager can download and install gems to your system and allows you to use the gems in other Ruby programs. Ruby 1.9 comes with RubyGems installed by default. If you are using a version prior to Ruby 1.9, you can download RubyGems here. To use RubyGems in a pre Ruby 1.9 app, you will need add this line in your app: require 'rubygems' Ruby 1.9 does not need this line, since RubyGems is included in the language. Gem Specification As I mentioned before, the gem specification describes the gem. Let’s take a look at a basic gemspec file:     Gem::Specification.new do |s|   s.name = %q{my_gem}   s.version = "0.0.1"   s.date = %q{2011-09-29}   s.summary = %q{my_gem is an awesome gem}   s.files = [     "Gemfile",     "Rakefile",     "VERSION",     "lib/my_gem.rb"   ]   s.require_paths = ["...

RuntimeError: redirection forbidden facebook image not creating in rails?

RuntimeError: redirection forbidden facebook image not creating in rails ? 1)gem 'open_uri_redirections' 2)models private   def process_uri(uri)     require 'open-uri'     require 'open_uri_redirections'     open(uri, :allow_redirections => :safe) do |r|       r.base_uri.to_s     end   end   3)if auth.info.image.present?    avatar_url = process_uri(auth.info.image)    user.update_attribute(:avatar, URI.parse(avatar_url)) end

Setting Up a Cloudfront CDN for Rails

Setting Up a Cloudfront CDN for Rails? Implementing a CDN to serve compiled assets in Rails is one of the most significant performance enhancements I’ve seen. Having done so for 2 fairly large applications, it’s hard for me to imagine serving assets locally anymore. The Asset Pipeline The addition of the Rails asset pipeline has reduced both the number of assets served and the size of these files. Users on slow connections have been the biggest beneficiary of these changes. The Problem Even with the asset pipeline, content is transmitted to the end user over their, sometimes slow, connection. Distance plays a role in the speed at which data can be delivered. Because of this, users further away from your servers get a sluggish experience. This decreases both the users’ patience and your ability to effectively engage them. The Solution CDNs are networks of servers that host your content so that when you make a request, the request is served from a server closest to you. This can often...

Caching in Rails with memcached?

Caching in Rails with memcached ? Installation 1. Follow this link to download and install memcached. 2. Start the memcached server using either memcached -vv or /etc/init.d/memcached start Integrating memcached with your rails application. 1. Install memcache-client gem install memcache-client 2. Add the below line to  end of your config/environment.rb file. CACHE = MemCache.new('127.0.0.1') 3. Add the following method to your application controller / application helper or where ever you want according to your need. def perform_cache(key)   begin    unless output = CACHE.get(key)      output = yield      CACHE.set(key, output, 15.minutes)    end  rescue => e   logger.info “MEMCACHE ERROR++++++++++++++++++++++++++++++++++++”   logger.info “ERROR : #{e.message}”   logger.info “MEMCACHE ERROR++++++++++++++++++++++++++++++++++++”   output = yield   en...