Rails_3

Similar documents
UNIST_교원 홈페이지 관리자_Manual_V1.0

PowerPoint Presentation

Microsoft PowerPoint - web-part03-ch19-node.js기본.pptx

DocsPin_Korean.pages

2파트-07

untitled

3장

BEef 사용법.pages

Cache_cny.ppt [읽기 전용]

I T C o t e n s P r o v i d e r h t t p : / / w w w. h a n b i t b o o k. c o. k r

1217 WebTrafMon II

1

Ext JS À¥¾ÖÇø®ÄÉÀ̼ǰ³¹ß-³¹Àå.PDF

Eclipse 와 Firefox 를이용한 Javascript 개발 발표자 : 문경대 11 년 10 월 26 일수요일

thesis

Week13

ETL_project_best_practice1.ppt

<C0CCBCBCBFB52DC1A4B4EBBFF82DBCAEBBE7B3EDB9AE2D D382E687770>

Remote UI Guide

PowerPoint 프레젠테이션

What is ScienceDirect? ScienceDirect는 세계 최대의 온라인 저널 원문 데이터베이스로 엘스비어에서 발행하는 약,00여 종의 Peer-reviewed 저널과,000여권 이상의 도서를 수록하고 있습니다. Peer review Subject 수록된

10.ppt

untitled

Orcad Capture 9.x

ORANGE FOR ORACLE V4.0 INSTALLATION GUIDE (Online Upgrade) ORANGE CONFIGURATION ADMIN O

Social Network

LXR 설치 및 사용법.doc

블로그_별책부록

구축환경 OS : Windows 7 그외 OS 의경우교재 p26-40 참조 Windows 의다른버전은조금다르게나타날수있음 Browser : Google Chrome 다른브라우저를사용해도별차이없으나추후수업의모든과정은크롬사용 한

13주-14주proc.PDF


chapter4

Javascript.pages

Analytics > Log & Crash Search > Unity ios SDK [Deprecated] Log & Crash Unity ios SDK. TOAST SDK. Log & Crash Unity SDK Log & Crash Search. Log & Cras

C H A P T E R 2

14-Servlet

ibmdw_rest_v1.0.ppt

3ÆÄÆ®-14

Mobile Service > IAP > Android SDK [ ] IAP SDK TOAST SDK. IAP SDK. Android Studio IDE Android SDK Version (API Level 10). Name Reference V

DIY 챗봇 - LangCon

Solaris Express Developer Edition

6강.hwp

PowerPoint Template

Intra_DW_Ch4.PDF

chapter1,2.doc

교육2 ? 그림

Portal_9iAS.ppt [읽기 전용]

untitled

HTML5가 웹 환경에 미치는 영향 고 있어 웹 플랫폼 환경과는 차이가 있다. HTML5는 기존 HTML 기반 웹 브라우저와의 호환성을 유지하면서도, 구조적인 마크업(mark-up) 및 편리한 웹 폼(web form) 기능을 제공하고, 리치웹 애플리케이 션(RIA)을

thesis-shk

untitled

PowerPoint 프레젠테이션

SK Telecom Platform NATE

목차 BUG offline replicator 에서유효하지않은로그를읽을경우비정상종료할수있다... 3 BUG 각 partition 이서로다른 tablespace 를가지고, column type 이 CLOB 이며, 해당 table 을 truncate

MySQL-Ch10

1

PowerChute Personal Edition v3.1.0 에이전트 사용 설명서

Mars OS System Administration Guide

MPLAB C18 C

Modern Javascript

歯처리.PDF

슬라이드 1

Connection 8 22 UniSQLConnection / / 9 3 UniSQL OID SET


MySQL-Ch05

소프트웨어개발방법론

초보자를 위한 C++

PRO1_09E [읽기 전용]

API STORE 키발급및 API 사용가이드 Document Information 문서명 : API STORE 언어별 Client 사용가이드작성자 : 작성일 : 업무영역 : 버전 : 1 st Draft. 서브시스템 : 문서번호 : 단계 : Docum

Polly_with_Serverless_HOL_hyouk

11강-힙정렬.ppt

PowerPoint Presentation

Dialog Box 실행파일을 Web에 포함시키는 방법

PowerPoint 프레젠테이션

3 S Q L A n t i p a t t e r n s Trees/intro/parent.sql CREATE TABLE Comments ( comment_id SERIAL PRIMARY KEY, parent_id BIGINT UNSIGNED, comment TEXT

02 C h a p t e r Java

untitled

untitled

Copyright 2012, Oracle and/or its affiliates. All rights reserved.,,,,,,,,,,,,,.,..., U.S. GOVERNMENT END USERS. Oracle programs, including any operat

CD-RW_Advanced.PDF

Intro to Servlet, EJB, JSP, WS

TITLE

초보자를 위한 ADO 21일 완성

Macaron Cooker Manual 1.0.key

NoSQL

10X56_NWG_KOR.indd

1. efolder 시스템구성 A. DB B. apache - mod-perl - PHP C. SphinxSearch ( 검색서비스 ) D. File Storage 2. efolder 설치순서 A. DB (MySQL) B. efolder Service - efolder

디지털포렌식학회 논문양식

PowerPoint 프레젠테이션

PowerPoint 프레젠테이션

초보자를 위한 ASP.NET 21일 완성

untitled

Chapter 1

FileMaker 15 WebDirect 설명서

No Slide Title

VOL /2 Technical SmartPlant Materials - Document Management SmartPlant Materials에서 기본적인 Document를 관리하고자 할 때 필요한 세팅, 파일 업로드 방법 그리고 Path Type인 Ph

I T C o t e n s P r o v i d e r h t t p : / / w w w. h a n b i t b o o k. c o. k r

Interstage5 SOAP서비스 설정 가이드

07 자바의 다양한 클래스.key

The Self-Managing Database : Automatic Health Monitoring and Alerting

Transcription:

Quick Reference Ruby on Rails

Appix B, (Curt Hibbs What Is Ruby on Rails InVisible GmbHd InVisible Ruby On Rails Reference 1 1 2 API http api rubyonrails com http creativecommons org licenses by sa 2 5 http www hanbitbook co kr exam 1453 What Is Ruby on Rails 2005 10 ONLamp com http www onlamp com pub a onlamp 2005 10 13 what is rails html InVisible Ruby On Rails Reference 1 1 2 Creative Commons http blog invisible ch files rails reference 1 1 html 197

API gem_server http localhost 8088 API http api rubyonrails com API http rails outertrack com http railshelp com http ruby doc org API HTML CSS DOM http www gotapi com WEBrick Mongrel Lighttpd Apache MS IIS http wiki rubyonrails org rails pages FAQ#webservers 198

DB2 Firebird MySQL Oracle PostgreSQL SQLite SQL Server http wiki rubyonrails org rails pages DatabaseDrivers Eclipse RDT http rubyeclipse sourceforge net FreeRIDE http freeride rubyforge org RadRails Eclipse RDT http www radrails org RDE Ruby Development Environment http homepage2 nifty com sakazuki rde_e html ArachnoRuby http www ruby ide com ruby ruby_ide_and_ruby_editor php 199

Komodo http www activestate com Products Komodo http wiki rubyonrails org rails pages Editors development log test log production log Interactive Rails Console http wiki rubyonrails com rails pages Console http www clarkware com cgi blosxom 2006 04 04 http wiki rubyonrails com rails pages HowtoDebugWithBreakpoint IDE http www bigbold com snippets posts show 697 rails app_name -d=xxx or --database=xxx mysql oracle postgresql sqlite3 mysql -r=xxx or --ruby-path=xxx 200

env -f or -freeze vor rails rake test rake test:functionals rake test:integration rake test:units #. #. #. #. rake test:units assertion assert_kind_of Class, @var # assert @var # nil assert_equal 1, @p.id # @product.destroy assert_raise(activerecord::recordnotfound) { Product.find( @product.id ) } rake test:functionals get :action # GET get :action, :id => 1, { session_hash }, # { flash_hash } # post :action, :foo => { :value1 => 'abc', :value2 => '123' }, { :user_id => 17 }, { :message => 'success' } get, post, put, delete, head 201

assert_response :success # # :success # :redirect # :missing # :error assert_redirected_to :action => :other_action assert_redirected_to :controller => 'foo', :action => 'bar' assert_redirected_to http://www.invisible.ch assert_template "post/index" assert_nil assigns(:some_variable) assert_not_nil assigns(:some_variable) assert_equal 17, assigns(:posts).size assert_tag :tag => 'body' assert_tag :content => 'Rails Seminar' assert_tag :tag => 'div', :attributes => { :class => 'index_list' } assert_tag :tag => 'head', :parent => { :tag => 'body' } assert_tag :tag => 'html', :child => { :tag => 'head' } assert_tag :tag => 'body', :descant => { :tag => 'div' } assert_tag :tag => 'ul', :children => { :count => 1..3, :only => { :tag => 'li' } } rake test:integration require "#{File.dirname( FILE )}/../test_helper" 202

class UserManagementTest < ActionController::IntegrationTest fixtures :users, :preferences def test_register_new_user get "/login" assert_response :success assert_template "login/index" get "/register" assert_response :success assert_template "register/index" post "/register", :user_name => "happyjoe", :password => "neversad" assert_response :redirect follow_redirect! assert_response :success assert_template "welcome" http jamis jamisbuck org articles 2006 03 09 integration testing in rails 1 1 http manuals rubyonrails com read book 5 rake make rake rake db:fixtures:load rake db:migrate rake db:schema:dump rake db:schema:load #. # FIXTURES=x,y. # db/migrate #. # VERSION=x. # db/schema.rb. # DB. # schema.rb. 203

rake db:sessions:clear #. rake db:sessions:create # CGI::Session::ActiveRecordStore #. rake db:structure:dump # SQL. rake db:test:clone # #. rake db:test:clone_structure # #. rake db:test:prepare #,. rake db:test:purge #. rake doc:app rake doc:clobber_app rake doc:clobber_plugins rake doc:clobber_rails rake doc:plugins rake doc:rails rake doc:reapp rake doc:rerails # HTML. # rdoc. #. # rdoc. #. # HTML. # RDOC. # RDOC. rake log:clear # log/ *.log # 0. rake rails:freeze:edge rake rails:freeze:gems rake rails:unfreeze # Edge Rails. # REVISION=x. # gems. # (vor/rails ) # gems edge #. rake rails:update # public/javascripts. rake rails:update:javascripts # javascripts. rake rails:update:scripts # script. rake stats # (KLOC ). rake test rake test:functionals rake test:integration rake test:plugins rake test:recent rake test:uncommitted rake test:units #. # functionalsdb:test:prepare. # integrationdb:test:prepare. # pluginsenvironment. # recentdb:test:prepare. # uncommitteddb:test:prepare. # unitsdb:test:prepare. 204

rake tmp:cache:clear rake tmp:clear rake tmp:create rake tmp:sessions:clear rake tmp:sockets:clear # tmp/cache. # tmp/,. #,, tmp. # tmp/sessions. # tmp/sessions ruby_sess. *. script/about script/breakpointer script/console script/destroy script/generate script/plugin script/runner script/server # #. # #. # -> # -> #. #. # http://localhost:3000 script/performance/profiler script/performance/benchmarker #. #. script/process/reaper script/process/spawner ruby script/generate model ModellName ruby script/generate controller ListController show edit ruby script/generate scaffold ModelName ControllerName ruby script/generate migration AddNewTable ruby script/generate plugin PluginName ruby script/generate mailer Notification lost_password signup ruby script/generate web_service ServiceName api_one api_two ruby script/generate integration_test TestName ruby script/generate session_migration -p or --pret 205

-f or --force -s or --skip -q or --quiet -t or --backtrace -h or --help -c or --svn subversion svn script/plugin discover #. script/plugin list #. script/plugin install where # "where". script/plugin install -x where # where SVN external. script/plugin install http://invisible.ch/projects/plugins/where script/plugin update #. script/plugin source #. script/plugin unsource #. script/plugin sources #. http wiki rubyonrails com rails pages Plugins http www agilewebdevelopment com plugins update_page do page page.insert_html :bottom, 'list', "<li>#{@item.name}</li>" 206

page.visual_effect :highlight, 'list' page.hide 'status-indicator', 'cancel-link' new Insertion.Bottom("list", "<li>some item</li>"); new Effect.Highlight("list"); ["status-indicator", "cancel-link"].each(element.hide); http api rubyonrails com classes ActionView Helpers PrototypeHelper JavaScriptGenerator GeneratorMethods html http www codyfauser com articles 2005 11 20 rails rjs templates http scottraymond net articles 2005 12 01 real world rails rjs templates http www rubynoob com articles 2006 05 13 simple rails rjs tutorial Tables classes Rows objects instances of model classes Columns object attributes Invoice invoices Person people Country countries SecurityLevel security_levels 207

http api rubyonrails com classes ActiveRecord Base html 4 B 1 B 2 has_one has_many belongs_to has_and_belongs_to_many def Order < ActiveRecord::Base has_many :line_items belongs_to :customer # "customer_id". def LineItem < ActiveRecord::Base belongs_to :order # "order_id". def Customer < ActiveRecord::Base has_many :orders has_one :address def Address < ActiveRecord::Base belongs_to :customer belongs_to :some_model, :class_name => 'MyClass', #. :foreign_key => 'my_real_id', #. :conditions => 'column = 0' # #. has_one :some_model, # belongs_to : :depent => :destroy #. :order => 'name ASC' # SQL has_many :some_model # has_one : 208

:depent => :destroy :depent => :delete_all :depent => :nullify :group => 'name' :finder_sql => 'select...' :counter_sql => 'select...' def Category < ActiveRecord::Base has_and_belongs_to_many :products def Product < ActiveRecord::Base has_and_belongs_to_many :categories # destroy #. # destroy #. #, #. # GROUP BY. # # 209

categories_products category_id product_id id class Author < ActiveRecord::Base has_many :authorships has_many :books, :through => :authorships class Authorship < ActiveRecord::Base belongs_to :author belongs_to :book class Book < ActiveRecord::Base has_one :authorship @author = Author.find :first @author.authorships.collect { a a.book } #. 210

@author.books # Authorship #. has_many class Firm < ActiveRecord::Base has_many :clients has_many :invoices, :through => :clients has_many :paid_invoices, :through => :clients, :source => :invoice class Client < ActiveRecord::Base belongs_to :firm has_many :invoices class Invoice < ActiveRecord::Base belongs_to :client @firm = Firm.find :first @firm.clients.collect { c c.invoices }.flatten # #. @firm.invoices # Client. http api rubyonrails com classes ActiveRecord Associations ClassMethods html validates_presence_of :firstname, :lastname #. validates_length_of :password, :minimum => 8 # 8 :maximum => 16 # 16 :in => 8..16 # 8 16 :too_short => 'way too short' :too_long => 'way to long' validates_acceptance_of :eula :accept => 'Y' #. # :1( ) 211

validates_confirmation_of :password # password_confirmation. validates_uniqueness_of :user_name # user_name. :scope => 'account_id' # : # account_id = user.account _id validates_format_of :email #. :with => /^(+)@((?:[-a-z0-9]+/.)+[a-z]{2,})$/i validates_numericality_of :value #. :only_integer => true :allow_nil => true validates_inclusion_in :ger, :in => %w( m, f ) #. validates_exclusion_of :age :in => 13..19 #. # 10. validates_associated :relation # :message => 'my own errormessage' :on => :create # :update (.) :if =>... # oder Proc. http api rubyonrails com classes ActiveRecord Validations html Person.average :age Person.minimum :age Person.maximum :age Person.count Person.count(:conditions => "age > 26") Person.sum :salary, :group => :last_name 212

http api rubyonrails com classes ActiveRecord Calculations ClassMethods html find(42) find([37, 42]) find :all find :first, :conditions => [ "name =?", "Hans" ] # id 42 # id 37, 42 # #. :order => 'name DESC' # SQL :offset => 20 # 20. :limit => 10 # 10. :group => 'name' # 'GROUP BY' SQL :joins => 'LEFT JOIN...' # LEFT JOIN.( ) :include => [:account, :fris] # LEFT OUTER JOIN. :include => { :groups => { :members=> { :favorites } } } :select => [:name, :adress] # SELECT * FROM. :readonly => true # Person.find_by_user_name(user_name) Person.find_all_by_last_name(last_name) Person.find_by_user_name_and_password(user_name, password) Order.find_by_name("Joe Blow") Order.find_by_email("jb@gmail.com") Slideshow.find_or_create_by_name("Winter") http api rubyonrails com classes ActiveRecord Base html Employee.with_scope( :find => { :conditions => "salary > 10000", :limit => 10 }) do 213

Employee.find(:all) # => SELECT * FROM employees # WHERE (salary > 10000) # LIMIT 10 #. Employee.with_scope( :find => { :conditions => "name = 'Jamis'" }) do Employee.find(:all) # => SELECT * FROM employees # WHERE ( salary > 10000 ) # AND ( name = 'Jamis' )) # LIMIT 10 #. Employee.with_exclusive_scope( :find => { :conditions => "name = 'Jamis'" }) do Employee.find(:all) # => SELECT * FROM employees # WHERE (name = 'Jamis') http www codyfauser com articles 2006 02 01 using with_scope to refactor messy finders http blog caboo se articles 2006 02 22 nested with_scope acts as list class TodoList < ActiveRecord::Base has_many :todo_items, :order => "position" class TodoItem < ActiveRecord::Base belongs_to :todo_list acts_as_list :scope => :todo_list 214

todo_list.first.move_to_bottom todo_list.last.move_higher http api rubyonrails com classes ActiveRecord Acts List ClassMethods html http api rubyonrails com classes ActiveRecord Acts List InstanceMethodshtml acts as tree class Category < ActiveRecord::Base acts_as_tree :order => "name" Example : root /_ child1 /_ subchild1 /_ subchild2 root = Category.create("name" => "root") child1 = root.children.create("name" => "child1") subchild1 = child1.children.create("name" => "subchild1") root.parent # => nil child1.parent # => root root.children # => [child1] root.children.first.children.first # => subchild1 http api rubyonrails com classes ActiveRecord Acts Tree ClassMethods html B 1 215

class Subscription < ActiveRecord::Base before_create :record_signup private def record_signup self.signed_up_on = Date.today class Firm < ActiveRecord::Base # before_destroy { record Person.destroy_all "firm_id = #{record.id}" } before_destroy { record Client.destroy_all "client_of = #{record.id}" } http api rubyonrails com classes ActiveRecord Callbacks html 216

Observer class CommentObserver < ActiveRecord::Observer def after_save(comment) Notifications.deliver_comment("admin@do.com", "New comment was posted", comment) app model model_observer rb config environment rb config.active_record.observers = :comment_observer, :signup_observer http api rubyonrails com classes ActiveRecord Observer html > ruby script/generate migration MyAddTables db migrations 001_my_add_tables rb up down def self.up #. create_table :table, :force => true do t t.column :name, :string t.column :age, :integer, { :default => 42 } t.column :description, :text # :string, :text, :integer, :float, :datetime, :timestamp, :time, # :date, :binary, :boolean add_column :table, :column, :type rename_column :table, :old_name, :new_name change_column :table, :column, :new_type execute "SQL Statement" add_index :table, :column, :unique => true, :name => 'some_name' add_index :table, [ :column1, :column2 ] 217

def self.down #. rename_column :table, :new_name, :old_name remove_column :table, :column drop_table :table remove_index :table, :column > rake db:migrate > rake db:migrate VERSION=14 > rake db:migrate RAILS_ENV=production http api rubyonrails org classes ActiveRecord Migration html http glu ttono us articles 2005 10 27 the joy of migrations http jamis jamisbuck org articles 2005 09 27 getting started with activerecord migrations public controller action URL world hello class WorldController < ApplicationController def hello rer :text => 'Hello world' GET POST params /world/hello/1?foo=bar id = params[:id] # 1 foo = params[:foo] # bar 218

def show @person = Person.find( params[:id]) def index @posts = Post.find :all respond_to do type type.html # weblog/index.rhtml type.xml { rer :action => "index.rxml" } type.js { rer :action => "index.rjs" } http api rubyonrails com classes ActionController Base html rer :action => 'some_action' #. "some_ action" #. rer :action => 'another_action', :layout => false rer :action => 'some_action', :layout => 'another_layout' _ _error _subform _listitem rer :partial => 'subform' rer :partial => 'error', :status => 500 rer :partial => 'subform', :locals => { :variable => @other_variable } 219

rer :partial => 'listitem', :collection => @list rer :partial => 'listitem', :collection => @list, :spacer_template => 'list_divider' app views rer :template => 'weblog/show' # app/views/weblog/show. rer :file => '/path/to/some/file.rhtml' rer :file => '/path/to/some/filenotfound.rhtml', status => 404, :layout => true rer :text => "Hello World" rer :text => "This is an error", :status => 500 rer :text => "Let's use a layout", :layout => true rer :text => 'Specific layout', :layout => 'special' ERb rer :inline => "<%= 'hello, ' * 3 + 'again' %>" rer :inline => "<%= 'hello ' + name %>", :locals => { :name => "david" } def refresh rer :update do page page.replace_html 'user_list', :partial => 'user', :collection => @users page.visual_effect :highlight, 'user_list' 220

rer :action => "atom.rxml", :content_type => "application/atom+xml" redirect_to(:action => "edit") redirect_to(:controller => "accounts", :action => "signup") rer :nothing rer :nothing, :status => 403 # http api rubyonrails com classes ActionView Base html http api rubyonrails com classes ActionController Base html config routes rb map.connect '', :controller => 'posts', :action => 'list' # map.connect ':action/:controller/:id' map.connect 'tasks/:year/:month', :controller => 'tasks', :action => 'by_date', :month => nil, :year => nil, :requirements => {:year => //d {4}/, :month => //d{1,2}/ } http manuals rubyonrails com read chapter 65 221

before_filter :login_required, :except => [ :login ] before_filter :autenticate, :only => [ :edit, :delete ] after_filter :compress proc before_filter { controller false if controller.params["stop_action"] } prep_before_filter prep_after_filter prep_before_filter some_filter some_filter skip_before_filter :some_filter skip_after_filter :some_filter http api rubyonrails com classes ActionController Filters ClassMethods html session[:user] = @user flash[:message] = "Data was saved successfully" <%= link_to "login", :action => 'login' unless session[:user] %> <% if flash[:message] %> <div><%= h flash[:message] %></div> <% %> session :off session :off, :only => :action session :off, :except => :action session :only => :foo, :session_secure => true #. # :action. # :action. # HTTPS :foo. 222

session :off, :only => :foo, # foo. :if => Proc.new { req req.parameters[:ws] } http api rubyonrails com classes ActionController Session Management ClassMethods html cookies[:user_name] = "david" # =>. cookies[:login] = { :value => "XJ-122", :expires => Time.now + 3600} # => 1. cookies[:user_name] # => "david" cookies.size # => 2 cookies.delete :user_name value path domain expires Time secure HTTPS 223

http api rubyonrails com classes ActionController Cookies html app views * rhtml HTML ERB * rxml XML Builder * rjs headers request response params session 224

controller RHTML HTML <% %> #. <%= %> #. <ul> <% @products.each do p %> <li><%= h @p.name %></li> <% %> </ul> HTML HTML h HTML <%=h @user_entered_notes %> XML xml.instruct! # <?xml version="1.0" encoding= "UTF-8"?> xml.comment! "a comment" # <!-- a comment --> xml.feed "xmlns" => "http://www.w3.org/2005/atom" do xml.title "My Atom Feed" xml.subtitle h(@feed.subtitle), "type" => 'html' xml.link url_for( :only_path => false, :controller => 'feed', :action => 'atom' ) xml.updated @updated.iso8601 xml.author do xml.name "Jens-Christian Fischer" xml.email "jcfischer@gmail.com" @entries.each do entry 225

xml.entry do xml.title entry.title xml.link "href" => url_for ( :only_path => false, :controller => 'entries', :action => 'show', :id => entry ) xml.id entry.urn xml.updated entry.updated.iso8601 xml.summary h(entry.summary) http rubyforge org projects builder HTML XML select DOM page.select('pattern' # CSS pattern. # select('p'), select('p.welcome b') page.select('div.header em').first.hide page.select('#items li').eacj do value value.hide insert_html DOM page.insert_html :position, id, content :top :bottom :before :after 226

replace_html DOM inner HTML page.replace_html 'title', "This is the new title" page.replace_html 'person-45', :partial => 'person', :object => @person replace DOM HTML page.replace 'task', :partial => 'task', :object => @task remove DOM page.remove 'edit-button' hide DOM page.hide 'some-element' show DOM page.show 'some-element' toggle DOM page.toggle 'some-element' alert page.alert 'Hello world' redirect_to page.redirect_to :controller => 'blog', :action => 'show', :id => @post 227

call page.call foo, 1, 2 assign page.assign "foo", 42 page << "alert('hello world);" delay page.delay(10) do page.visual_effect :fade, notice visual_effect Scriptaculous page.visual_effect :highlight, 'notice', :duration => 2 sortable page.sortable 'my_list', :url => { :action => 'order' } dragable page.dragable 'my_image', :revert => true drop_receiving page.drop_recieving 'my_cart', :url => { :controller => 'cart', :action => 'add' } 228

http api rubyonrails com classes ActionView Base html app helpers app helpers application_helper rb link_to "Name", :controller => 'post', :action => 'show', :id => @post.id link_to "Delete", { :controller => "admin", :action => "delete", :id => @post }, { :class => 'css-class', :id => 'css-id', :confirm => "Are you sure?" } image_tag "spinner.png", :class => "image", :alt => "Spinner" mail_to "info@invisible.ch", "s mail", :subject => "Support request by #{@user.name}", :cc => @user.email, :body => '...', :encoding => "javascript" stylesheet_link_tag "scaffold", "admin", :media => "all" http api rubyonrails com classes ActionView Helpers UrlHelper html 229

<%= form_tag { :action => :save }, { :method => :post } %> POST MIME multipart = true <%= text_field :modelname, :attribute_name, options %> <input type="text" name="modelname[attribute_name]" id= "attributename" /> text_field "post", "title", "size" => 20 <input type="text" id="post_title" name="post[title]" size="20" value="#{@post.title}" /> <%= hidden_field... %> * <%= password_field... %> <%= file_field... %> <%= text_area... %> text_area "post", "body", "cols" => 20, "rows" => 40 <textarea cols="20" rows="40" id="post_body" name="post[body]"> 230

#{@post.body} </textarea> <%= radio_button :modelname, :attribute, :tag_value, options %> radio_button "post", "category", "rails" radio_button "post", "category", "java" <input type="radio" id="post_category" name=" post[category]" value="rails" checked="checked" /> <input type="radio" id="post_category" name=" post[category]" value="java" /> <%= check_box :modelname, :attribute, options, on_value, off_value %> check_box "post", "validated" # post.validated? 1 0. <input type="checkbox" id="post_validate" name=" post[validated]" value="1" checked="checked" /> <input name="post[validated]" type="hidden" value="0" /> check_box "puppy", "gooddog", {}, "yes", "no" <input type="checkbox" id="puppy_gooddog" name="puppy [gooddog]" value="yes" /> <input name="puppy[gooddog]" type="hidden" value="no" /> select <%= select :variable, :attribute, choices, options, html_options %> select "post", "person_id", Person.find_all.collect { p [ p.name, p.id ] }, { :include_blank => true } <select name="post[person_id]"> 231

<option></option> <option value="1" selected="selected">david</option> <option value="2">sam</option> <option value="3">tobias</option> </select> <%= collection_select :variable, :attribute, choices, :id, :value %> <%= date_select :variable, :attribute, options %> <%= datetime_select :variable, :attribute, options %> date_select "post", "written_on" date_select "user", "birthday", :start_year => 1910 date_select "user", "cc_date", :start_year => 2005, :use_month_numbers => true, :discard_day => true, :order => [:year, :month] datetime_select "post", "written_on" <%= _form_tag %> http api rubyonrails com classes ActionView Helpers FormHelper html HTML app views layouts <html> <head> <title>form: <%= controller.action_name %></title> <%= stylesheet_link_tag 'scaffold' %> </head> 232

<body> <%= yield %> #. </body> </html> ---- class MyController < ApplicationController layout "standard", :except => [ :rss, :atom ]... ---- class MyOtherController < ApplicationController layout :compute_layout # def compute_layout return "admin" if session[:role] == "admin" "standard"... http api rubyonrails com classes ActionController Layout ClassMethods html rer :partial => 'product' _product rhtml @product @product rer :partial => 'product', :locals => { :product => @bought } 233

rer :partial => 'product', :collection => @product_list @product_list @product partial_name_counter product_ counter http api rubyonrails com classes ActionView Partials html <%= javascript_include_tag :defaults %> <%= link_to_remote "link", :update => 'some_div', :url => { :action => 'show', :id => post.id } %> <%= link_to_remote "link", :url => { :action => 'create', :update => { :success => 'good_div', :failure => 'error_div' }, :loading => 'Element.show('spinner'), :complete => 'Element.hide('spinner') } %> loading loaded 234

interactive success XMLHttpRequest HTTP 2XX failure XMLHttpRequest HTTP 2XX complete XMLHttpRequest success failure complete link_to_remote word, :url => { :action => "action" }, 404 => "alert('not found...? Wrong URL...?')", :failure => "alert('http Error ' + request.status + '!')" POST XMLHttpRequest params html action form_remote_tag :html => { :action => url_for(:controller => 'controller', :action => 'action'), :method => :post } 235

<%= text_field_with_auto_complete :model, :attribute %> auto_complete_for :model, :attribute <label for="search">search term:</label> <%= text_field_tag :search %> <%= observe_field(:search, :frequency => 0.5, :update => :results, :url => { :action => :search }) %> <div id="results"></div> :on => :blur # ( :changed :clicked) :with =>... # # : "value" :with => 'bla' # "'bla' = value" :with => 'a=b' # "a=b" observe_field <%= periodically_call_remote(:update => 'process-list', :url => { :action => :ps }, :frequency => 2 ) %> http api rubyonrails com classes ActionView Helpers JavaScriptHelper html 236

config environment rb config.action_controller.session_store = :active_record_store # active_record_store :drb_store # :mem_cache_store :memory_store ActionController::Base.session_options[:session_key] = 'my_app' # session_key. ActionController::Base.session_options[:session_id] = '12345' # session_id.. ActionController::Base.session_options[:session_expires] = 3.minute.from_now # ActionController::Base.session_options[:new_session] = true #. ActionController::Base.session_options[:session_secure] = true # HTTPS. ActionController::Base.session_options[:session_domain] = 'invisible.ch' #.( ) ActionController::Base.session_options[:session_path] = '/my_app' #. # CGI. http api rubyonrails com classes ActionController Session Management ClassMethods html ActionController::Base.fragment_cache_store = :file_store, "/path/to/cache/directory" http api rubyonrails com classes ActionController Caching html 237

61, 166, 184, 201, 211 80 123 66 236 236 217 170, 178, 180, 201 232 81, 87 73 170, 173 199 145, 150 200 200 29 231 118 189, 191, 194 115, 232 API 198 219 193 194 198 206 202, 221 81 229 45, 46, 95, 217 15, 41 221 198 111 87 134, 229 98 57 128, 219, 233 224 200 21 222 222 154 172 15, 91, 96 205 33 119, 135 49, 53, 54 23, 189 219 28, 29 15, 38, 207 208 231 49 201 35 118 21, 198 201 191 189 108 236 48 87 52 205 231 238

87 237 218 50 215, 217 223 87 166 167 166 194 230 230 220 199 170, 184 62 81 41 60, 213 38, 65 230 33 222 172 221 1:1 75, 209 1:N 209 :depent 73 :include 73 :rer_layout 144 :through 80 << 228 <div> 133 FILE 174 Action Pack 28 acts_as_list 81, 82, 83, 214 acts_as_nested_set 81 acts_as_tree 81, 84, 215 Ajax 139, 234 alert 227 assertion 166, 201 assert_redirected_to 184 assert_template 184 assign 228 belongs_to 66, 70, 72, 82, 83 call 228 Capistrano 187 collect 129 collection_select 126, 162 composed_of 57, 58 content_columns 101 content_type 221 CRUD 92 CSV 172 delay 228 dispatcher 29 down 68 dragable 228 draggable_element 155 drop_receiving 228 drop_receiving_element 153, 155, 159 each_with_index 147 Eclipse 191, 199 _form 232 ERb 108 exclusively_depent 73 File.dirname 174 Finders 213 find_all 60 find_by_< > 60 find_by_sql 60 Fixtures 172 flash 222 gem 17 h 113 h() 225 has_and_belongs_to_many 76, 78, 80 239

has_many 72, 74 has_one 70, 75 hide 227 HTML 225 human_name 101 image_tag 108, 113 index 93 insert_html 226 Instant Rails 189 javascript_include_tag 144, 234 layout 117 lighttpd 23, 193 link_to 113, 114 link_to_remote 234 Locomotive 193 M:N 76 method_missing 53 Model2 16 Mongrel 24 MV 16 MySQL 189 N:1 66 nested set 81 Observe Field 236 Observe Form 236 Observers 217 observe_field 153, 162 paginate 114 params 147 params 218 parent_id 84 partial 128 periodically_call_remote 143, 236 Plug-ins 206 prep_after_filter 222 prep_before_filter 222 Prototype 141 RadRails 189, 191, 194, 199 redirect_to 227 remove 227 rer_scaffold 93 replace 227 replace_html 227 RHTML 225 RJS 206, 220, 226 RXML 225 scaffold 91, 92, 96 SciTE 191 script.aculo.us 141 script/generate 25 select 226 Selenium 186 session 222 show 227 sortable 228 sortable_element 147, 158 SQLite 193 stylesheet_link_tag 121 Test::Unit 166, 168, 174 Test::Unit::TestCase 166, 168, 174 TextMate 194 through 80 toggle 227 Type 187 up 68 URL 221 url_for 113 visual_effect 228 WEBrick 23, 191 XMLHttpRequest 140, 235 xunit 166 YAML 172 ZenTest 186 240