Skip to content

Instantly share code, notes, and snippets.

@tyrotinal
tyrotinal / gist:5530345
Created May 7, 2013 05:00
rails: migrate in production
RAILS_ENV=production rake db:migrate
@tyrotinal
tyrotinal / gist:5530348
Created May 7, 2013 05:00
rails: procfile sample
web: bundle exec rails s -p 8080
@tyrotinal
tyrotinal / gist:5530349
Created May 7, 2013 05:01
rake: assets precompile
rake assets:precompile
@tyrotinal
tyrotinal / gist:5530351
Created May 7, 2013 05:01
rake: db create
rake db:create
@tyrotinal
tyrotinal / gist:5530355
Created May 7, 2013 05:02
railsHowto: set different layout for different controller
##Layout for different controllers
`app/controllers/dashboard_controller.rb`
class DashboardController < ApplicationController
before_filter :authenticate_user!
def index
render :layout => "dashboard"
end
@tyrotinal
tyrotinal / gist:5530358
Created May 7, 2013 05:02
rails: form helper 1
<h2>Register</h2>
<%= form_for :user do |form| %>
<fieldset>
<legend>Enter Your Details</legend>
<div class="form_row">
<label for="screen_name">Screen name:</label>
<%= form.text_field :screen_name %>
</div>
<div class="form_row">
<label for="email">Email:</label>
@tyrotinal
tyrotinal / gist:5530363
Created May 7, 2013 05:04
rails: simple for loop to sum numbers from 1 to 5
<h1>Simple for loop</h1>
<h1>Here we are going to count</h1>
<p>This is a simple for loop</p>
<% sum = 0 %>
<% for i in 1..5 %>
<% sum = sum+i %>
<h3><%= "sum is #{sum}" %></h3>
<% end %>
@tyrotinal
tyrotinal / gist:5530366
Created May 7, 2013 05:04
railsHowTo: using application helpers
##Application helpers
Using application helps methods can be defined to simplify method callings in views.
First, define the helper in:
`app/helpers/application_helper.rb`
module ApplicationHelper
def title
base = "Sample app"
@tyrotinal
tyrotinal / gist:5530368
Created May 7, 2013 05:05
rails: simple class
class User
attr_accessor :name, :email
def initialize(attributes = {})
@name = attributes[:name]
@email = attributes[:email]
end
def formatted_email
"#{@name} <#{@email}>"
end
end
@tyrotinal
tyrotinal / gist:5530372
Created May 7, 2013 05:05
rails: calling the class called User
user = User.new(:name => "Michael Hartl", :email => "[email protected]")
user.formatted_email