Method: ActionText::Attachable.from_node

Defined in:
actiontext/lib/action_text/attachable.rb

.from_node(node) ⇒ Object

Extracts the ActionText::Attachable from the attachment HTML node:

person = Person.create! name: "Javan"
html = %Q(<action-text-attachment sgid="#{person.attachable_sgid}"></action-text-attachment>)
fragment = ActionText::Fragment.wrap(html)
attachment_node = fragment.find_all(ActionText::Attachment.tag_name).first
ActionText::Attachable.from_node(attachment_node) # => person


31
32
33
34
35
36
37
38
39
40
41
# File 'actiontext/lib/action_text/attachable.rb', line 31

def from_node(node)
  if attachable = attachable_from_sgid(node["sgid"])
    attachable
  elsif attachable = ActionText::Attachables::ContentAttachment.from_node(node)
    attachable
  elsif attachable = ActionText::Attachables::RemoteImage.from_node(node)
    attachable
  else
    ActionText::Attachables::MissingAttachable.new(node["sgid"])
  end
end