mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Add some simple examples for unconventional AMo and AP use
This commit is contained in:
parent
b20d68446d
commit
45d41d8012
5 changed files with 89 additions and 0 deletions
50
actionpack/examples/very_simple.rb
Normal file
50
actionpack/examples/very_simple.rb
Normal file
|
@ -0,0 +1,50 @@
|
|||
$:.push "rails/activesupport/lib"
|
||||
$:.push "rails/actionpack/lib"
|
||||
|
||||
require "action_controller"
|
||||
|
||||
class Kaigi < ActionController::Http
|
||||
include AbstractController::Callbacks
|
||||
include ActionController::RackConvenience
|
||||
include ActionController::Renderer
|
||||
include ActionController::Layouts
|
||||
include ActionView::Context
|
||||
|
||||
before_filter :set_name
|
||||
append_view_path "views"
|
||||
|
||||
def _action_view
|
||||
self
|
||||
end
|
||||
|
||||
def controller
|
||||
self
|
||||
end
|
||||
|
||||
DEFAULT_LAYOUT = Object.new.tap {|l| def l.render(*) yield end }
|
||||
|
||||
def _render_template_from_controller(template, layout = DEFAULT_LAYOUT, options = {}, partial = false)
|
||||
ret = template.render(self, {})
|
||||
layout.render(self, {}) { ret }
|
||||
end
|
||||
|
||||
def index
|
||||
render :template => "template"
|
||||
end
|
||||
|
||||
def alt
|
||||
render :template => "template", :layout => "alt"
|
||||
end
|
||||
|
||||
private
|
||||
def set_name
|
||||
@name = params[:name]
|
||||
end
|
||||
end
|
||||
|
||||
app = Rack::Builder.new do
|
||||
map("/kaigi") { run Kaigi.action(:index) }
|
||||
map("/kaigi/alt") { run Kaigi.action(:alt) }
|
||||
end.to_app
|
||||
|
||||
Rack::Handler::Mongrel.run app, :Port => 3000
|
1
actionpack/examples/views/layouts/alt.html.erb
Normal file
1
actionpack/examples/views/layouts/alt.html.erb
Normal file
|
@ -0,0 +1 @@
|
|||
+ <%= yield %> +
|
1
actionpack/examples/views/layouts/kaigi.html.erb
Normal file
1
actionpack/examples/views/layouts/kaigi.html.erb
Normal file
|
@ -0,0 +1 @@
|
|||
Hello <%= yield %> Goodbye
|
1
actionpack/examples/views/template.html.erb
Normal file
1
actionpack/examples/views/template.html.erb
Normal file
|
@ -0,0 +1 @@
|
|||
Hello <%= @name %>
|
36
activemodel/examples/amo_ap_example.rb
Normal file
36
activemodel/examples/amo_ap_example.rb
Normal file
|
@ -0,0 +1,36 @@
|
|||
$:.push "activesupport/lib"
|
||||
$:.push "activemodel/lib"
|
||||
|
||||
require "active_model/validations"
|
||||
require "active_model/deprecated_error_methods"
|
||||
require "active_model/errors"
|
||||
require "active_model/naming"
|
||||
|
||||
class Person
|
||||
include ActiveModel::Validations
|
||||
extend ActiveModel::Naming
|
||||
|
||||
validates_presence_of :name
|
||||
|
||||
attr_accessor :name
|
||||
def initialize(attributes = {})
|
||||
@name = attributes[:name]
|
||||
end
|
||||
|
||||
def persist
|
||||
@persisted = true
|
||||
end
|
||||
|
||||
def new_record?
|
||||
@persisted
|
||||
end
|
||||
|
||||
def to_model() self end
|
||||
end
|
||||
|
||||
person1 = Person.new
|
||||
p person1.valid?
|
||||
person1.errors
|
||||
|
||||
person2 = Person.new(:name => "matz")
|
||||
p person2.valid?
|
Loading…
Reference in a new issue