Module: ScaffoldLogic

Defined in:
lib/scaffold_logic.rb,
lib/scaffold_logic/helper.rb,
lib/scaffold_logic/data_import.rb,
lib/scaffold_logic/form_helper.rb,
lib/scaffold_logic/menu_helper.rb,
lib/scaffold_logic/tab_interface_helper.rb,
lib/generators/scaffold_logic/layout/layout_generator.rb,
lib/generators/scaffold_logic/scaffold/scaffold_generator.rb

Overview

Configuration

Configure your application to default to the custom form builder

In app/controllers/application_controller.rb:

class ApplicationController < ActionController::Base
  ActionView::Base.default_form_builder = ScaffoldLogic::FormBuilder

Usage

Default form field with label:

<%= f.text_field :last_name -%>

Returns:

<fieldset>
  <label for="user_last_name">Last Name</label>
  <input id="user_last_name" name="user[last_name]" size="30" type="text" />
</fieldset>

Form field with custom label:

<%= f.text_field :first_name, :label => 'Custom' -%>

Returns:

<fieldset>
  <label for="user_first_name">Custom</label>
  <input id="user_first_name" name="user[first_name]" size="30" type="text" />
</fieldset>

Form field with no label

<%= f.text_field :search, :label => false -%>

Returns:

<input id="search" name="search" size="30" type="text" />

Form field with inline help (? icon which reveals help content when clicked):

<%= f.password_field :password %>

Returns:

<fieldset>
  <label for="password">Password: <img src="/images/icons/help_icon.png"
  onclick="$('#password_help').toggle();" class='inline_icon' /></label>
  <div class="inline_help" id="password_help" style="display: none;">
    <p>Here are some detailed instructions on valid passwords.</p>
  </div>
  <input id="user_password" name="user[password]" size="30" type="password" />
</fieldset>

Form field with instructions (show immediately below the label):

<%= f.password_field :password_confirmation %>

Returns:

<fieldset>
  <label for="password_confirmation">
    Confirm Password:
    <span class="instructions">Enter your password again to confirm.</span>
  </label>
  <input id="user_password_confirmation" name="user[password_confirmation]" size="30" type="password" />
</fieldset>

Check box with label in addition to checkbox value text

(E.g. ‘Foo’ appears above the checkbox, and ‘Something’ next to it):

<%= f.check_box :foo, :inline_label => 'Something' -%>

Returns:

<fieldset>
  <label for="user_foo">Foo</label>
  <input name="user[foo]" type="hidden" value="0" />
  <input id="user_foo" name="user[foo]" type="checkbox" value="1" />
  <label class="inline" for="user_foo">Something</label>
</fieldset>

Don’t wrap fields in a fieldset

<%= f.text_field :query, :label => 'Search terms:', :fieldset => false -%>

Returns

<label for="search_terms_query">
<input id="search_terms_query" name="search_terms_query" size="30" />

Troubleshooting

If you’re seeing double form labels, it’s because you still have <%= label -%> elements in your forms.

Defined Under Namespace

Modules: FormHelper, Generators, Helper, MenuHelper, TabInterfaceHelper Classes: DataImport, FormBuilder

Class Method Summary collapse

Class Method Details

.mongoid_sorter_from(field, direction) ⇒ Object



179
180
181
182
183
# File 'lib/scaffold_logic.rb', line 179

def self.mongoid_sorter_from( field, direction )
  field ||= 'id'
  direction ||= 'asc'
  eval ":#{field}.#{direction}"
end