Module: Orange::Pulp::ScaffoldHelpers

Defined in:
lib/orange-core/resources/scaffold.rb

Instance Method Summary collapse

Instance Method Details

Creates a button that appears to be a link but does form submission with custom method (_method param in POST) This is to avoid issues of a destructive get.

Parameters:

  • text (String)

    link text to show

  • link (String)

    the actual href value of the link

  • confirm (String, false) (defaults to: false)

    text of the javascript confirm (false for none [default])

  • args (optional, Array)

    array of optional arguments, only opts defined

  • opts (Hash) (defaults to: {})

    a customizable set of options

Options Hash (opts):

  • method (String)

    method name (Should be ‘DELETE’, ‘PUT’ or ‘POST’)



105
106
107
108
109
110
111
112
113
114
# File 'lib/orange-core/resources/scaffold.rb', line 105

def form_link(text, link, confirm = false, opts = {})
  text = "<img src='#{opts[:img]}' alt='#{text}' />" if opts[:img]
  css = opts[:class]? opts[:class] : 'form_button_link'
  meth = (opts[:method]? "<input type='hidden' name='_method' value='#{opts[:method]}' />" : '')
  if confirm
    "<form action='#{link}' method='post' class='mini' onsubmit='return confirm(\"#{confirm}\")'><button class='link_button'><a href='#' class='#{css}'>#{text}</a></button>#{meth}</form>"
  else
    "<form action='#{link}' method='post' class='mini'><button class='link_button'><a href='#' class='#{css}'>#{text}</a></button>#{meth}</form>"
  end
end

#view(model_name, *args) ⇒ Object

Calls view for an orange resource.



117
118
119
# File 'lib/orange-core/resources/scaffold.rb', line 117

def view(model_name, *args)
  orange[model_name].view(self, *args)
end

#view_attribute(prop, model_name, *args) ⇒ Object

Returns a scaffolded attribute



122
123
124
# File 'lib/orange-core/resources/scaffold.rb', line 122

def view_attribute(prop, model_name, *args)
  orange[:scaffold].scaffold_attribute(self, prop, model_name, *args)
end