Skip to content

Instantly share code, notes, and snippets.

@rvalyi
Last active August 29, 2015 14:00
Show Gist options
  • Save rvalyi/11392464 to your computer and use it in GitHub Desktop.
Save rvalyi/11392464 to your computer and use it in GitHub Desktop.
# somewhere in the Rails app initialization:
require 'dragonfly'
Ooor::Base.extend Dragonfly::Model
Ooor::Base.extend Dragonfly::Model::Validations
Ooor.xtend('product.product') do
dragonfly_accessor :dragon_image do
after_assign :resize_image
end
def resize_image
dragon_image.process!(:thumb, '64x64>')
end
end
<!-- in the a form view, object set as ooor_session['product.product'] -->
<%= ooor_form_for(object, url: (object.new? ? ooorest.create_path(model_path) : ooorest.update_path(model_path, object.id)),
html: {class: 'form-horizontal'}) do |f| %>
<% if object.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(object.errors.count, "error") %> prohibited this form from being saved:</h2>
<ul>
<% object.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="actions row">
<%= f.ooor_input :name %>
<%= f.input :dragon_image, as: 'file' %>
</div>
<div class="actions row">
<%= f.button :submit, class: 'btn btn-primary btn-lg' %>
</div>
<% end %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment