This series introduces students to ruby on rails 3 through the book "Agile Web Development with Rails" with accompanying lecture videos found at http://www.thinkbohemian.com/tag/rails-summer-of-code/
This is the 2nd of 8 presentations given at University of Texas during my Beginner to Builder Rails 3 Class. For more info and the whole series including video presentations at my blog:
http://schneems.tumblr.com/tagged/Rails-3-beginner-to-builder-2011
This document contains notes from a Rails training session. It discusses variables in Ruby and Rails, controllers, testing controllers, associations between database tables, and many-to-many relationships. Key topics covered include using instance variables to share data between models and views, testing controller actions, the params hash, and setting up belongs_to, has_many, has_many :through, and HABTM associations.
This document provides an introduction to Swift 2 and covers various Swift language basics including variables and constants, arrays, optionals, functions and closures, classes, structs, enums, protocols, and generics. It discusses syntax, properties, methods and gives examples for each language feature. The document is organized into sections for each language concept and provides code samples and explanations.
Rapid Application Development using Ruby on RailsSimobo
This document outlines a 4 day training course on rapid application development using Ruby on Rails. Day 1 covers an overview of Ruby on Rails, setting up the development environment, and conducting live demos. Day 2 delves deeper into model-view-controller architecture, database migrations, and form helpers. Day 3 focuses on testing, Active Record optimizations, and unobtrusive JavaScript. Day 4 explores supporting gems for features like caching, file uploads, searching, and delayed jobs. Each day includes lectures, code examples, and hands-on practice building a sample Rails application.
Code for Startup MVP (Ruby on Rails) Session 2Henry S
This document provides an overview and agenda for a workshop on learning to code for startup MVPs using Ruby on Rails. It covers setting up the development environment, a review of concepts from the previous session, and a focus on Ruby basics, Rails models, and using Devise for user authentication.
(RubyFools 2008)
"Plugins are more than just shiny nuggets of code which rain down from the higher echelons of the Rails pantheon; they are loyal and useful servants that anyone can employ to help reuse code between applications. Without a little guidance, however, the process of figuring out just how to tame these beasts can be overwhelming.
"This presentation will help give developers the boost that's often required to get up to speed developing plugins. We'll cover the hooks that Rails' plugin mechanism makes available, and how to put them to best use in practice.
"Once we've covered the groundwork, we'll start to look at more advanced programming techniques for sharing code (and other files) between Rails applications. With a few key programming techniques under our belt, we can use plugins to alter and enhance the Rails framework itself, and become masters of Ruby's object model along the way."
The document discusses using jQuery for Ajax support. It introduces the $.ajax function for making Ajax requests with jQuery and describes some of its basic syntax and options. Examples are provided to demonstrate using $.ajax to make an Ajax request and update the page based on the response.
This is the 2nd of 8 presentations given at University of Texas during my Beginner to Builder Rails 3 Class. For more info and the whole series including video presentations at my blog:
http://schneems.tumblr.com/tagged/Rails-3-beginner-to-builder-2011
This document contains notes from a Rails training session. It discusses variables in Ruby and Rails, controllers, testing controllers, associations between database tables, and many-to-many relationships. Key topics covered include using instance variables to share data between models and views, testing controller actions, the params hash, and setting up belongs_to, has_many, has_many :through, and HABTM associations.
This document provides an introduction to Swift 2 and covers various Swift language basics including variables and constants, arrays, optionals, functions and closures, classes, structs, enums, protocols, and generics. It discusses syntax, properties, methods and gives examples for each language feature. The document is organized into sections for each language concept and provides code samples and explanations.
Rapid Application Development using Ruby on RailsSimobo
This document outlines a 4 day training course on rapid application development using Ruby on Rails. Day 1 covers an overview of Ruby on Rails, setting up the development environment, and conducting live demos. Day 2 delves deeper into model-view-controller architecture, database migrations, and form helpers. Day 3 focuses on testing, Active Record optimizations, and unobtrusive JavaScript. Day 4 explores supporting gems for features like caching, file uploads, searching, and delayed jobs. Each day includes lectures, code examples, and hands-on practice building a sample Rails application.
Code for Startup MVP (Ruby on Rails) Session 2Henry S
This document provides an overview and agenda for a workshop on learning to code for startup MVPs using Ruby on Rails. It covers setting up the development environment, a review of concepts from the previous session, and a focus on Ruby basics, Rails models, and using Devise for user authentication.
(RubyFools 2008)
"Plugins are more than just shiny nuggets of code which rain down from the higher echelons of the Rails pantheon; they are loyal and useful servants that anyone can employ to help reuse code between applications. Without a little guidance, however, the process of figuring out just how to tame these beasts can be overwhelming.
"This presentation will help give developers the boost that's often required to get up to speed developing plugins. We'll cover the hooks that Rails' plugin mechanism makes available, and how to put them to best use in practice.
"Once we've covered the groundwork, we'll start to look at more advanced programming techniques for sharing code (and other files) between Rails applications. With a few key programming techniques under our belt, we can use plugins to alter and enhance the Rails framework itself, and become masters of Ruby's object model along the way."
The document discusses using jQuery for Ajax support. It introduces the $.ajax function for making Ajax requests with jQuery and describes some of its basic syntax and options. Examples are provided to demonstrate using $.ajax to make an Ajax request and update the page based on the response.
This document provides an introduction to the Ruby programming language. It discusses that Ruby is an object-oriented language designed by Yukihiro "Matz" Matsumoto to be focused on humans rather than machines. It emphasizes that everything in Ruby is an object and covers key Ruby concepts like variables, methods, classes, modules, mixins, blocks, and syntax. The document encourages learning more about Ruby through interactive tutorials and code exercises.
Yet another talk :)
This time in a lecture called “Markup Languages und Anwendungen”
Went pretty ok, but as usual I talked a little bit too fast ^_^
http://www.marc-seeger.de
The document outlines an agenda for a PHP crash course, beginning with an introduction to the speaker's background and qualifications. It then covers the basics of PHP including its history, why it's popular, how to get started, basic syntax and types, variables, constants, expressions, control structures, functions, classes and objects. The document recommends additional advanced PHP topics and reading materials.
Swift is a modern, safe, and interactive programming language. It is fast, supports modern features like closures and generics, and is type safe with static typing and ARC memory management. The document provides an overview of key Swift concepts like variables and constants, basic types, optionals, collection types like arrays and dictionaries, control flow, and switch statements. Examples are given for working with strings, integers, floating point numbers, collections, and optional values.
The document discusses several Swift Evolution proposals including:
- Implicit returns from single-expression functions and closures which allows omitting the return keyword from functions/closures with a single expression.
- Opaque result types which allow abstracting away types using some to preserve type identity and information hiding.
- The Identifiable protocol which provides a standard way to identify values based on an ID property to enable change tracking in SwiftUI lists and other APIs.
- Property wrappers which define custom attributes to encapsulate property storage and behavior, eliminating boilerplate and providing patterns to define properties like @State, @Binding, @Published etc.
The document discusses object-oriented programming concepts in Objective-C such as classes, objects, properties, memory management using retain, release and autorelease, class and instance methods. It provides examples of declaring classes with interfaces and implementations, initializing objects, and accessing properties using dot syntax. Memory management is handled through retain counts, and autorelease pools are used to avoid memory leaks.
This presentation is based on Joakim\’s experiences from moving from Java to Scala http://www.scala-lang.org/node/960#Joak We will explore how to move from Java to Scala and why. We\’ll look at things that you will run into sooner rather than later such as Scala\’s collection APIs, Options and higher order functions and special syntax. You will leave this presentation with good foundation to use Scala in practice; perhaps even in your current Java project and ideally with an appetite to learn more.
1. Swift includes features like subscripts, optional chaining, and error handling that improve safety and flexibility compared to earlier languages.
2. The document discusses Swift concepts like extensions, protocols, and generics that allow code reuse and abstraction. Protocols define requirements that types can conform to through extensions.
3. Generics allow algorithms to work with different types through type parameters like Stack<Element>, avoiding duplicate non-generic code. This makes code cleaner, safer, and more reusable.
What's a macro?: Learning by Examples / Scalaのマクロに実用例から触れてみよう!scalaconfjp
Macros allow code to generate code by replacing expressions during compilation. They enable simplifying code and improving efficiency. While macros are powerful, their implementation can be complex, requiring knowledge of compiler internals. The scala.meta library aims to simplify metaprogramming by representing programs as trees without losing information, making macros easier to write without deep compiler expertise.
The document provides an overview of the Swift programming language, summarizing that it is fast, modern, and safe. It then covers key Swift concepts like variables, strings, arrays, dictionaries, optionals, control flow, functions, closses, classes, inheritance, enums, structs, protocols, extensions, and generics in under 3 sentences each. The document encourages learning more about Swift from Apple's official documentation.
The document discusses the advantages of Scala over Java for programming. It notes that Scala is more expressive than Java as it supports features like lambdas, mixins and functional programming. Scala also benefits from a variety of libraries and high performance while running on the JVM. The document encourages readers to start with Scala by exploring an example module that uses magic.
PHP 8.0 is expected to be released by the end of the year, so it’s time to take a first look at the next major version of PHP. Attributes, union types, and a just-in-time compiler are likely the flagship features of this release, but there are many more improvements to be excited about. As PHP 8.0 is a major version, this release also includes backwards-incompatible changes, many of which are centered around stricter error handling and more type safety.
This talk will discuss new features already implemented in PHP 8, backwards-compatibility breaks to watch out for, as well as some features that are still under discussion.
This document provides an overview of the Ruby programming language. It discusses that Ruby is a dynamic, multi-paradigm language influenced by Perl, Smalltalk, Lisp and other languages. The document then covers various aspects of the Ruby language like its object model, syntax, classes, modules and libraries. It concludes by providing some literature references and links for learning Ruby.
The document discusses differences between Ruby and Scala programming languages. Some key similarities include both being class-based object-oriented languages with functional features. Differences include Scala using explicit types while Ruby is dynamically typed, and Scala having separate concepts of methods and functions while Ruby blurs the distinction. The document also compares features like class definitions, collections, functions as values, and enhancing existing classes.
The document discusses Ruby classes and objects. It shows that everything in Ruby is an object, including classes. Classes are instances of the Class class. The hierarchy of built-in classes is:
- BasicObject
- Object
- Module
- Class
It demonstrates that all objects inherit from BasicObject and classes inherit from Module. The document uses method calls like .class, .is_a?, and .superclass to explore and illustrate these relationships between Ruby objects and classes.
This is an introduction to relational and non-relational databases and how their performance affects scaling a web application.
This is a recording of a guest Lecture I gave at the University of Texas school of Information.
In this talk I address the technologies and tools Gowalla (gowalla.com) uses including memcache, redis and cassandra.
Find more on my blog:
http://schneems.com
This is the last of 8 presentations given at University of Texas during my Beginner to Builder Rails 3 Class. For more info and the whole series including video presentations at my blog:
http://schneems.com/tagged/Rails-3-beginner-to-builder-2011
This is the 6th of 8 presentations given at University of Texas during my Beginner to Builder Rails 3 Class. For more info and the whole series including video presentations at my blog:
http://schneems.com/tagged/Rails-3-beginner-to-builder-2011
This is the 5th of 8 presentations given at University of Texas during my Beginner to Builder Rails 3 Class. For more info and the whole series including video presentations at my blog:
http://schneems.com/tagged/Rails-3-beginner-to-builder-2011
This is the 4th of 8 presentations given at University of Texas during my Beginner to Builder Rails 3 Class. For more info and the whole series including video presentations at my blog:
http://schneems.com/tagged/Rails-3-beginner-to-builder-2011
This document provides an introduction to the Ruby programming language. It discusses that Ruby is an object-oriented language designed by Yukihiro "Matz" Matsumoto to be focused on humans rather than machines. It emphasizes that everything in Ruby is an object and covers key Ruby concepts like variables, methods, classes, modules, mixins, blocks, and syntax. The document encourages learning more about Ruby through interactive tutorials and code exercises.
Yet another talk :)
This time in a lecture called “Markup Languages und Anwendungen”
Went pretty ok, but as usual I talked a little bit too fast ^_^
http://www.marc-seeger.de
The document outlines an agenda for a PHP crash course, beginning with an introduction to the speaker's background and qualifications. It then covers the basics of PHP including its history, why it's popular, how to get started, basic syntax and types, variables, constants, expressions, control structures, functions, classes and objects. The document recommends additional advanced PHP topics and reading materials.
Swift is a modern, safe, and interactive programming language. It is fast, supports modern features like closures and generics, and is type safe with static typing and ARC memory management. The document provides an overview of key Swift concepts like variables and constants, basic types, optionals, collection types like arrays and dictionaries, control flow, and switch statements. Examples are given for working with strings, integers, floating point numbers, collections, and optional values.
The document discusses several Swift Evolution proposals including:
- Implicit returns from single-expression functions and closures which allows omitting the return keyword from functions/closures with a single expression.
- Opaque result types which allow abstracting away types using some to preserve type identity and information hiding.
- The Identifiable protocol which provides a standard way to identify values based on an ID property to enable change tracking in SwiftUI lists and other APIs.
- Property wrappers which define custom attributes to encapsulate property storage and behavior, eliminating boilerplate and providing patterns to define properties like @State, @Binding, @Published etc.
The document discusses object-oriented programming concepts in Objective-C such as classes, objects, properties, memory management using retain, release and autorelease, class and instance methods. It provides examples of declaring classes with interfaces and implementations, initializing objects, and accessing properties using dot syntax. Memory management is handled through retain counts, and autorelease pools are used to avoid memory leaks.
This presentation is based on Joakim\’s experiences from moving from Java to Scala http://www.scala-lang.org/node/960#Joak We will explore how to move from Java to Scala and why. We\’ll look at things that you will run into sooner rather than later such as Scala\’s collection APIs, Options and higher order functions and special syntax. You will leave this presentation with good foundation to use Scala in practice; perhaps even in your current Java project and ideally with an appetite to learn more.
1. Swift includes features like subscripts, optional chaining, and error handling that improve safety and flexibility compared to earlier languages.
2. The document discusses Swift concepts like extensions, protocols, and generics that allow code reuse and abstraction. Protocols define requirements that types can conform to through extensions.
3. Generics allow algorithms to work with different types through type parameters like Stack<Element>, avoiding duplicate non-generic code. This makes code cleaner, safer, and more reusable.
What's a macro?: Learning by Examples / Scalaのマクロに実用例から触れてみよう!scalaconfjp
Macros allow code to generate code by replacing expressions during compilation. They enable simplifying code and improving efficiency. While macros are powerful, their implementation can be complex, requiring knowledge of compiler internals. The scala.meta library aims to simplify metaprogramming by representing programs as trees without losing information, making macros easier to write without deep compiler expertise.
The document provides an overview of the Swift programming language, summarizing that it is fast, modern, and safe. It then covers key Swift concepts like variables, strings, arrays, dictionaries, optionals, control flow, functions, closses, classes, inheritance, enums, structs, protocols, extensions, and generics in under 3 sentences each. The document encourages learning more about Swift from Apple's official documentation.
The document discusses the advantages of Scala over Java for programming. It notes that Scala is more expressive than Java as it supports features like lambdas, mixins and functional programming. Scala also benefits from a variety of libraries and high performance while running on the JVM. The document encourages readers to start with Scala by exploring an example module that uses magic.
PHP 8.0 is expected to be released by the end of the year, so it’s time to take a first look at the next major version of PHP. Attributes, union types, and a just-in-time compiler are likely the flagship features of this release, but there are many more improvements to be excited about. As PHP 8.0 is a major version, this release also includes backwards-incompatible changes, many of which are centered around stricter error handling and more type safety.
This talk will discuss new features already implemented in PHP 8, backwards-compatibility breaks to watch out for, as well as some features that are still under discussion.
This document provides an overview of the Ruby programming language. It discusses that Ruby is a dynamic, multi-paradigm language influenced by Perl, Smalltalk, Lisp and other languages. The document then covers various aspects of the Ruby language like its object model, syntax, classes, modules and libraries. It concludes by providing some literature references and links for learning Ruby.
The document discusses differences between Ruby and Scala programming languages. Some key similarities include both being class-based object-oriented languages with functional features. Differences include Scala using explicit types while Ruby is dynamically typed, and Scala having separate concepts of methods and functions while Ruby blurs the distinction. The document also compares features like class definitions, collections, functions as values, and enhancing existing classes.
The document discusses Ruby classes and objects. It shows that everything in Ruby is an object, including classes. Classes are instances of the Class class. The hierarchy of built-in classes is:
- BasicObject
- Object
- Module
- Class
It demonstrates that all objects inherit from BasicObject and classes inherit from Module. The document uses method calls like .class, .is_a?, and .superclass to explore and illustrate these relationships between Ruby objects and classes.
This is an introduction to relational and non-relational databases and how their performance affects scaling a web application.
This is a recording of a guest Lecture I gave at the University of Texas school of Information.
In this talk I address the technologies and tools Gowalla (gowalla.com) uses including memcache, redis and cassandra.
Find more on my blog:
http://schneems.com
This is the last of 8 presentations given at University of Texas during my Beginner to Builder Rails 3 Class. For more info and the whole series including video presentations at my blog:
http://schneems.com/tagged/Rails-3-beginner-to-builder-2011
This is the 6th of 8 presentations given at University of Texas during my Beginner to Builder Rails 3 Class. For more info and the whole series including video presentations at my blog:
http://schneems.com/tagged/Rails-3-beginner-to-builder-2011
This is the 5th of 8 presentations given at University of Texas during my Beginner to Builder Rails 3 Class. For more info and the whole series including video presentations at my blog:
http://schneems.com/tagged/Rails-3-beginner-to-builder-2011
This is the 4th of 8 presentations given at University of Texas during my Beginner to Builder Rails 3 Class. For more info and the whole series including video presentations at my blog:
http://schneems.com/tagged/Rails-3-beginner-to-builder-2011
This is the first of 8 presentations given at University of Texas during my Beginner to Builder Rails 3 Class. For more info and the whole series including video presentations at my blog:
http://schneems.tumblr.com/tagged/Rails-3-beginner-to-builder-2011
This document summarizes content from Week 6 of the Rails Summer of Code. It discusses email in Rails, including how email works, content types, and using ActionMailer. It also covers background tasks in Rails using rake tasks, cron jobs, Monit, and God. Modules and mixins in Ruby are explained. Callbacks and observers in Rails are described as ways to trigger behavior during an object's lifecycle. Internationalization and localization in Rails are covered, including using the I18n module and creating language-specific YAML files.
This series introduces students to ruby on rails 3 through the book "Agile Web Development with Rails" with accompanying lecture videos found at http://www.thinkbohemian.com/tag/rails-summer-of-code/
This series introduces students to ruby on rails 3 through the book "Agile Web Development with Rails" with accompanying lecture videos found at http://www.thinkbohemian.com/tag/rails-summer-of-code/
This series introduces students to ruby on rails 3 through the book "Agile Web Development with Rails" with accompanying lecture videos found at http://www.thinkbohemian.com/tag/rails-summer-of-code/
ProSocial Behaviour - Applied Social Psychology - Psychology SuperNotesPsychoTech Services
A proprietary approach developed by bringing together the best of learning theories from Psychology, design principles from the world of visualization, and pedagogical methods from over a decade of training experience, that enables you to: Learn better, faster!
You may be stressed about revealing your cancer diagnosis to your child or children.
Children love stories and these often provide parents with a means of broaching tricky subjects and so the ‘The Secret Warrior’ book was especially written for CANSA TLC, by creative writer and social worker, Sally Ann Carter.
Find out more:
https://cansa.org.za/resources-to-help-share-a-parent-or-loved-ones-cancer-diagnosis-with-a-child/
As we navigate through the ebbs and flows of life, it is natural to experience moments of low motivation and dwindling passion for our goals.
However, it is important to remember that this is a common hurdle that can be overcome with the right strategies in place.
In this guide, we will explore ways to rekindle the fire within you and stay motivated towards your aspirations.
Aggression - Applied Social Psychology - Psychology SuperNotesPsychoTech Services
A proprietary approach developed by bringing together the best of learning theories from Psychology, design principles from the world of visualization, and pedagogical methods from over a decade of training experience, that enables you to: Learn better, faster!
Understanding of Self - Applied Social Psychology - Psychology SuperNotesPsychoTech Services
A proprietary approach developed by bringing together the best of learning theories from Psychology, design principles from the world of visualization, and pedagogical methods from over a decade of training experience, that enables you to: Learn better, faster!
Procrastination is a common challenge that many individuals face when it comes to completing tasks and achieving goals. It can hinder productivity and lead to feelings of stress and frustration.
However, with the right strategies and mindset, it is possible to overcome procrastination and increase productivity.
In this article, we will explore the causes of procrastination, how to recognize the signs of procrastination in oneself, and effective strategies for overcoming procrastination and boosting productivity.
3. Ruby
• Hashes - (Like a Struct)
• Key - Value Pairs - Different DataTypes Ok
hash = {:a => 100, :b => “hello”}
>> hash[:a]
=> 100
>> hash[:b]
=> hello
>> hash.keys
=> [:b, :a]
Richard Schneeman - @ThinkBohemian
4. Ruby
• Hashes in method parameters
• options (a hash) is optional parameter
def myMethod(variable, options = {})
puts variable
options.keys.each do |key|
puts options[key]
end
end
>> myMethod(“Hi”)
=> Hi
>> myMethod(“Hi”, :a => “hello” , “there”)
=> Hi
Hello
There
Richard Schneeman - @ThinkBohemian
5. Hashes in Rails
• Used heavily
• options (a hash) is optional parameter
Rails API: (ActionView::Helpers::FormHelper) text_area
Richard Schneeman - @ThinkBohemian
6. Hashes in Rails
• Used heavily
• options (a hash) is optional parameter
Rails API: (ActionView::Helpers::FormHelper) text_area
Richard Schneeman - @ThinkBohemian
7. Ruby
• Objects don’t have attributes
• Need getter & setter methods
class MyClass
def myAttribute=(value)
@myAttribute = value
end
def myAttribute
@myAttribute
end
end
>> object = MyClass.new
>> object.myAttribute = “foo”
>> object.myAttribute
=> “foo”
Richard Schneeman - @ThinkBohemian
8. Ruby
• Ruby gives us Class Macros !!
• Example: attr_accessor
class MyClass
attr_accessor :myAttribute
end
>> object = MyClass.new
>> object.myAttribute = “foo”
>> object.myAttribute
=> “foo”
Richard Schneeman - @ThinkBohemian
9. Ruby
• Class Methods
• (methods that can be run on the class)
class My_class
def myInstanceMethod(value)
puts value
end
def self.myClassMethod(value)
puts value
end
end
My_class.myClassMethod("foo")
=> "foo"
Richard Schneeman - @ThinkBohemian
10. Ruby
• Class Methods
• (methods that can be run on the class)
class My_class
def myInstanceMethod(value)
puts value
end
def self.myClassMethod(value)
puts value
end
end
My_class.myClassMethod("foo")
=> "foo"
Richard Schneeman - @ThinkBohemian
11. Ruby
• Instance Methods
class My_class
def myInstanceMethod(value)
puts value
end
def self.myClassMethod(value)
puts value
end
end
>> myInstance = My_class.new
>> myInstance.myInstanceMethod("foo")
=> “foo”
>> myInstance.myClassMethod(“bar”)
=> undefined method ‘myClassMethod’ for #<My_class:0x100124d18>
Richard Schneeman - @ThinkBohemian
12. Ruby
• Instance Methods
class My_class
def myInstanceMethod(value)
puts value
end
def self.myClassMethod(value)
puts value
end
end
>> myInstance = My_class.new
>> myInstance.myInstanceMethod("foo")
=> “foo”
>> myInstance.myClassMethod(“bar”)
=> undefined method ‘myClassMethod’ for #<My_class:0x100124d18>
Richard Schneeman - @ThinkBohemian
13. Ruby
• Instance Methods
class My_class
def myInstanceMethod(value)
puts value
end
def self.myClassMethod(value)
puts value
end
end
>> myInstance = My_class.new
>> myInstance.myInstanceMethod("foo")
=> “foo”
>> myInstance.myClassMethod(“bar”)
=> undefined method ‘myClassMethod’ for #<My_class:0x100124d18>
Richard Schneeman - @ThinkBohemian
14. Ruby
• Class Methods class Dog
• Have self
def self.find(name)
...
end
• Instance Methods
def wag_tail(frequency)
...
• Don’t (Have self)
end
end
Richard Schneeman - @ThinkBohemian
15. Ruby
• Class Methods class Dog
• Have self
def self.find(name)
...
end
• Instance Methods
def wag_tail(frequency)
...
• Don’t (Have self)
end
end
Richard Schneeman - @ThinkBohemian
16. Ruby
• attr_accessor is a Class method
attr_accessor :myAttribute
Can be defined as:
def self.attr_accessor(value)
...
end
cool !
Richard Schneeman - @ThinkBohemian
18. Scaffolding
• Generate Model, View, and Controller & Migration
>> rails generate scaffold Post name:string title:string content:text
• Generates “One Size Fits All” code
• app/models/post.rb
• app/controllers/posts_controller.rb
• app/views/posts/ {index, show, new, create, destroy}
• Modify to suite needs (convention over configuration)
Richard Schneeman - @ThinkBohemian
19. Migrations
• Create your data structure in your Database
• Set a database’s schema
migrate/create_post.rb
class CreatePost < ActiveRecord::Migration
def self.up
create_table :post do |t|
t.string :name
t.string :title
t.text :content
end
SystemSetting.create :name => "notice", :label => "Use notice?", :value => 1
end
def self.down
drop_table :posts
end
end
Richard Schneeman - @ThinkBohemian
20. Migrations
• Get your data structure into your database
>> rake db:migrate
• Runs all “Up” migrations
def self.up
create_table :post do |t|
t.string :name
t.string :title
t.text :content
end
end
Richard Schneeman - @ThinkBohemian
21. Migrations
• Creates a Table named post def self.up
create_table :post do |t|
• Adds Columns t.string
t.string
:name
:title
•
t.text :content
Name, Title, Content end
end
• created_at & updated_at
added automatically
Richard Schneeman - @ThinkBohemian
22. Migrations
• Creates a Table named post def self.up
create_table :post do |t|
• Adds Columns t.string
t.string
:name
:title
•
t.text :content
Name, Title, Content end
end
• created_at & updated_at
added automatically
Richard Schneeman - @ThinkBohemian
23. Migrations
• Active Record maps ruby objects to database
• Post.title
Active Record is Rail’s ORM
def self.up
create_table :post do |t|
t.string :name
t.string :title
t.text :content
end
end
Richard Schneeman - @ThinkBohemian
24. Migrations
• Active Record maps ruby objects to database
• Post.title
Active Record is Rail’s ORM
def self.up
create_table :post do |t|
t.string :name
t.string :title
t.text :content
end
end
Richard Schneeman - @ThinkBohemian
25. Migrations
• Active Record maps ruby objects to database
• Post.title
Active Record is Rail’s ORM
def self.up
create_table :post do |t|
t.string :name
t.string :title
t.text :content
end
end
Richard Schneeman - @ThinkBohemian
26. Migrations
• Active Record maps ruby objects to database
• Post.title
Active Record is Rail’s ORM
def self.up
create_table :post do |t|
t.string :name
t.string :title
t.text :content
end
end
Richard Schneeman - @ThinkBohemian
27. Migrations
• Active Record maps ruby objects to database
• Post.title
Active Record is Rail’s ORM
def self.up
create_table :post do |t|
t.string :name
t.string :title
t.text :content
end
end
Richard Schneeman - @ThinkBohemian
28. Migrations
• Made a mistake? Issue a database Ctrl + Z !
>> rake db:rollback
• Runs last “down” migration
def self.down
drop_table :system_settings
end
Richard Schneeman - @ThinkBohemian
29. Scaffolding
• Generate Model, View, and Controller
>> scaffold Post name:string title:string content:text
• models/post.rb
• controllers/posts_controller.rb
• views/post/{ index.html, show.html, new.html, create.html }
Richard Schneeman - @ThinkBohemian
30. Rails - Validations
• Check your parameters before save
• Provided by ActiveModel
• Utilized by ActiveRecord
class Person < ActiveRecord::Base
validates :title, :presence => true, :title => true
end
bob = Person.create(:title => nil)
>> bob.valid?
=> false
>> bob.save
=> false
Richard Schneeman - @ThinkBohemian
31. Rails - Validations
Can use ActiveModel without Rails
class Person
include ActiveModel::Validations
attr_accessor :title
validates :title, :presence => true, :title => true
end
bob = Person.create(:title => nil)
>> bob.valid?
=> false
>> bob.save
=> false
Richard Schneeman - @ThinkBohemian
32. Rails - Validations
• Use Rail’s built in Validations
# :acceptance => Boolean.
# :confirmation => Boolean.
# :exclusion => { :in => Ennumerable }.
# :inclusion => { :in => Ennumerable }.
# :format => { :with => Regexp, :on => :create }.
# :length => { :maximum => Fixnum }.
# :numericality => Boolean.
# :presence => Boolean.
# :uniqueness => Boolean.
• Write your Own Validations
class User < ActiveRecord::Base
validate :my_custom_validation
private
def my_custom_validation
self.errors.add(:password, "Custom Message") unless self.property.present?
end
end
Richard Schneeman - @ThinkBohemian
33. Testing
• Test your code (or wish you did)
• Makes upgrading and refactoring easier
• Different Environments
• production - live on the web
• development - on your local computer
• test - local clean environment
Richard Schneeman - @ThinkBohemian
34. Testing
• Unit Tests
• Test individual methods against known inputs
• Integration Tests
• Test Multiple Controllers
• Functional Tests
• Test full stack M- V-C
Richard Schneeman - @ThinkBohemian
35. Unit Testing
• ActiveSupport::TestCase
• Provides assert statements
• assert true
• assert (variable)
• assert_same( obj1, obj2 )
• many more
Richard Schneeman - @ThinkBohemian
36. Unit Testing
• Run Unit Tests using:
>> rake test:units RAILS_ENV=test
Richard Schneeman - @ThinkBohemian
37. Unit Testing
• Run Tests automatically the background
• ZenTest
• sudo gem install ZenTest
• Run:
>> autotest
Richard Schneeman - @ThinkBohemian