Class: RubyMVC::Views::ActiveRecordTypeEditor

Inherits:
View
  • Object
show all
Includes:
LinkDispatcher
Defined in:
lib/ruby_mvc/views/ar_type_editor.rb

Instance Attribute Summary

Attributes inherited from View

#controller, #widget

Instance Method Summary collapse

Methods included from LinkDispatcher

#link_activated

Methods inherited from View

create_widget, #method_missing, #peer, widget, widget_def

Constructor Details

#initialize(type, options = {}, &block) ⇒ ActiveRecordTypeEditor

Returns a new instance of ActiveRecordTypeEditor.



32
33
34
35
36
37
38
39
40
# File 'lib/ruby_mvc/views/ar_type_editor.rb', line 32

def initialize(type, options = {}, &block)
  ctrl = options[:controller] = options[:controller] || self
  super(options, &block)
  @type = type
  @list = active_record_type_list type
  para link("New...") {
    ctrl.link_activated(self, "/create_instance")
  }
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class RubyMVC::Views::View

Instance Method Details

#create_instance(sender, link) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/ruby_mvc/views/ar_type_editor.rb', line 42

def create_instance(sender, link)
  debug("create instance of type #{@type}")
  obj = @type.new
  window do
    stack do
      obj.description = "Some text"
      editor = active_record_model_editor obj
      flow :margin_left => 0, :left => "-25%" do
        button "Cancel", :align => "right" do 
          close 
        end
        button "Save", :align => "right" do
          editor.save
          close
        end
        debug("created buttons")
      end
    end
  end
end