Rails 4.1: deploying to Heroku

download the toolbelt kit: $ wget -O- https://toolbelt.heroku.com/install-ubuntu.sh | sh login: $ heroku login create your app: $ heroku apps:create [your app name] or, if you already have an app in Heroku: $ heroku git:remote -a ticketee-demo Add the rails_12factor gem, to take care of the standard points a web app should cover. In your gemfile: gem […]

rails 4.1: styling an app with bootstrap and font-awesome

Install the bootstrap gem: gem “bootstrap-sass”, “~> 3.3” gem “font-awesome-rails”, “~> 4.3” Rename app/assets/stylesheets/application.css to application.css.scss, so you an add @import statements to it Replace the entire content of the file with: @import “bootstrap-sprockets”; @import “bootstrap”; @import “font-awesome”; Once you do this, you will need to also import the particular stylesheets your app is compose […]

rails 4.1 helpers

helpers are methods inside your app/helpers folder, and they are available to your views usage. Every controller gets one (if the controller gets created via a generator). Example of an application helper: module ApplicationHelper def title(*parts) unless parts.empty? content_for :title do (parts << “Ticketee”).join(” – “) end end end end The * means any argument passed […]

rails 4.1: creating a CRUD resource feature

Create the test first, inside your specs/feature/ folder: spec/features/your_feature_name_spec.rb Sample content for that file: require “rails_helper” RSpec.feature “Users can create a project” do scenario “with valid attributes” do visit “/” click_link “New Project” fill_in “Name”, with: “Some Project name” fill_in “Description”, with: “Some project description” click_button “Create” expect(page).to have_content “Project has been created.” end end […]

rails projects workflow

setup your rails vagrant env and add git, by following the instructions in this page setup your IDE to be connected to your vagrant instance (inside Vagrantfile): config.vm.synced_folder “./src”, “/home/vagrant/your_project” setup the initial rails app: rails new myapp setup the bitbucket repo config and initialize your git repo: git config –global user.name “your name” git […]

bootstapping an angular.js app on top of rails

Complete example here – The following will skip jquery and turbolinks: rails new [your-app-name-here] –skip-javascript – But now you need to manually create the following file: app/assets/javascripts/application.js – And include the following in the file contents: //= require_tree . – put all your angular app files inside app/assets/javascripts, and include the following in your app/views/layouts/application.html.erb template: <%= javascript_include_tag […]

rails: handling errors for routes / controllers not found

Create a controller that will handle errors: class ErrorsController < ApplicationController   def routing     render_404   end   def render_404     render :json => {:status => “error”, :response_code => 404, :message => “no route found that match your request, please check your parameters and try again”, :results => {} }.to_json   end […]

Rails: barebones site template from the ground up, version II, using rails 4

Assuming you have rails 4 already running in your system. And git / heroku also ready to go. $ rails new your-project Add a bunch of static pages, remove the default page: remove public/index.html (if there) $ rails generate controller StaticPages home help about contact_us –no-test-framework Inside config/routes.rb” – Comment out the static pages you […]