0
+ # Produces a wrapper DIV element with id and class parameters that
0
+ # relate to the specified ActiveRecord object. Usage example:
0
+ # <% div_for(@person, :class => "foo") do %>
0
+ # <%=h @person.name %>
0
+ # <div id="person_123" class="person foo"> Joe Bloggs </div>
0
def div_for(record, *args, &block)
0
+ content_tag_for(:div, record, *args, &block)
0
+ # content_tag_for creates an HTML element with id and class parameters
0
+ # that relate to the specified ActiveRecord object. For example:
0
+ # <% content_tag_for(:tr, @person) do %>
0
+ # <td><%=h @person.first_name %></td>
0
+ # <td><%=h @person.last_name %></td>
0
+ # would produce hthe following HTML (assuming @person is an instance of
0
+ # a Person object, with an id value of 123):
0
+ # <tr id="person_123" class="person">....</tr>
0
+ # If you require the HTML id attribute to have a prefix, you can specify it:
0
+ # <% content_tag_for(:tr, @person, :foo) do %> ...
0
+ # <tr id="foo_person_123" class="person">...
0
+ # content_tag_for also accepts a hash of options, which will be converted to
0
+ # additional HTML attributes. If you specify a +:class+ value, it will be combined
0
+ # with the default class name for your object. For example:
0
+ # <% content_tag_for(:li, @person, :class => "bar") %>...
0
+ # <li id="person_123" class="person bar">...
0
+ def content_tag_for(tag_name, record, *args, &block)
0
prefix = args.first.is_a?(Hash) ? nil : args.shift
0
options = args.first.is_a?(Hash) ? args.shift : {}
0
- concat content_tag(
:div, capture(&block),
0
+ concat content_tag(
tag_name, capture(&block),
0
options.merge({ :class => "#{dom_class(record)} #{options[:class]}".strip, :id => dom_id(record, prefix) })),
0
@@ -18,8 +64,9 @@ module ActionView
0
when Hash, String, Symbol, NilClass
0
link_to_without_record_identification(attr_name, record, html_options, *parameters_for_method_reference)
0
- url = SimplyHelpful::RecordIdentifier.named_route(record, self)
0
- link_to_without_record_identification(record.send(attr_name), url, html_options, *parameters_for_method_reference)
0
+ url = SimplyHelpful::RecordIdentifier.polymorphic_url(record, self)
0
+ link_text = record.respond_to?(attr_name) ? record.send(attr_name) : attr_name
0
+ link_to_without_record_identification(link_text, url, html_options, *parameters_for_method_reference)
Comments
No one has commented yet.