Ruby on Rails: links

The official format is: link_to(name, options={}, html_options={}) In the templates, you can use it as: <%= link_to “Home”,    ‘home_path’ %> Everywhere else (example): link_to ‘New’, {controller: ‘articles’, action: ‘new’}, {class: ‘large’} First argument: The text that will show as part of the link Second argument: the name of the route we are invoking Third argument: options, anything else you […]

Ruby On Rails: Server side validation

It happens inside the model. All you have to do is: class Micropost < ActiveRecord::Base attr_accessible :content, :user_id validates :content, :length => { :maximum => 140 } end Rails 4.0 validates_presence_of :title, :body # make sure you have that field validates_uniqueness_of :email # Makes sure your email is unique across the system validates_uniqueness_of :teacher_id, :scope => [:semester_id, :class_id] # Validates that the teacher_id is unique for a […]

Apache: setup reverse proxy

Useful for situations where you need to hit APIs from websites that are not part of your domain, and you’d like to avoid the cross scripting limitations of JS without using jsonp go at the top level of the config: ProxyRequests On ProxyVia On Then setup the URL redirection: proxyPass /adapter/ http://thefinaldestinationhere/evenwith/subdirectories proxyPassReverse /adapter/ http://thefinaldestinationhere/evenwith/subdirectories This is […]