This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rake db:migrate |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rake db:create |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rake db:drop |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mailcatcher --ip=0.0.0.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
user = User.new(:name => "Michael Hartl", :email => "[email protected]") | |
user.formatted_email |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class User | |
attr_accessor :name, :email | |
def initialize(attributes = {}) | |
@name = attributes[:name] | |
@email = attributes[:email] | |
end | |
def formatted_email | |
"#{@name} <#{@email}>" | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
##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" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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 %> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
##Layout for different controllers | |
`app/controllers/dashboard_controller.rb` | |
class DashboardController < ApplicationController | |
before_filter :authenticate_user! | |
def index | |
render :layout => "dashboard" | |
end |