class Microframe::FormHelper
Attributes
form_started[R]
target[R]
target_id[R]
target_name[R]
Public Class Methods
new(target, target_link)
click to toggle source
# File lib/microframe/controller/form_helper.rb, line 5 def initialize (target, target_link) @target = target @target_name = target.class.to_s.downcase @link = target_link @form_started = false end
Public Instance Methods
check_box(name, val=nil)
click to toggle source
# File lib/microframe/controller/form_helper.rb, line 39 def check_box(name, val=nil) val ||= target.send(name) gatekeeper "<input type = 'checkbox' name = '#{target_name}[#{name}]' checked = '#{val}' value = 'true'/>" end
gatekeeper(output)
click to toggle source
# File lib/microframe/controller/form_helper.rb, line 50 def gatekeeper(output) form_started ? output : start_form + output end
label(name)
click to toggle source
# File lib/microframe/controller/form_helper.rb, line 19 def label(name) gatekeeper "<label>#{name}</label>" end
start_form()
click to toggle source
# File lib/microframe/controller/form_helper.rb, line 12 def start_form @form_started = true @target_id = target.id ? target.id : nil @link ||= "/#{target_name}s/#{target_id || ""}" "<form action='#{@link}' method='post'>" end
submit()
click to toggle source
# File lib/microframe/controller/form_helper.rb, line 31 def submit output = "" output += "<input type = 'hidden' name = '_method' value = 'put'/>" if target_id output += "<input type = 'submit' value = 'save' />" output += "</form>" gatekeeper output end
text_area(name)
click to toggle source
# File lib/microframe/controller/form_helper.rb, line 23 def text_area(name) gatekeeper "<textarea name = '#{target_name}[#{name}]'>#{target.send(name)}</textarea>" end
text_field(name)
click to toggle source
# File lib/microframe/controller/form_helper.rb, line 27 def text_field(name) gatekeeper "<input type = 'text' name = '#{target_name}[#{name}]' value = '#{target.send(name)}'/>" end