Paperclip Rails 3.2.2 Not Rotating and Resizing - ruby-on-rails-3

Paperclip gem 3.0.4
When I use flat Paperclip definition in Model (UserDetail has an avatar):
has_attached_file :avatar, :styles => {:medium => "300x300>", : :thumb => "64x64#" }
All images are created in correct proportions.
When I use a custom processor through lambda ( http://www.matthuggins.com/articles/rotating-paperclip-image-attachments-in-rails ):
has_attached_file :avatar, :processors => [:rotator], :styles => lambda { |a| {
:thumb => { :geometry => '64x64#', :rotation => a.instance.rotation, },
:medium => { :geometry => '300x300>', :rotation => a.instance.rotation, }, } }
The image is rotated by the specified amount but all images stay at the same size and proportions as the :original.
Is :geometry the right parameter? Has this changed in later version of Paperclip (I'm unsure of the version of Paperclip used in the web example)?
Any pointers gratefully received
Regards
Peter

one proc per style:
has_attached_file :avatar,
:processors => [:rotator],
:styles => {
:thumb => Proc.new { |a| { :geometry => '64x64#', :rotation => a.instance.rotation } },
:medium => Proc.new { |a| { :geometry => '300x300>', :rotation => a.instance.rotation } }
}

Related

Paperclip + S3 Amazon region error

I read a lot of stuff about this, but still i can't fix my error.
Error i got is: Aws::Errors::MissingRegionError (missing region; use :region option or export region name to ENV['AWS_REGION']):
My production.rb :
config.paperclip_defaults = {
:storage => :s3,
:region => 'eu-central-1',
:s3_credentials => {
:bucket => ENV['S3_BUCKET_NAME'],
:access_key_id => ENV['AWS_ACCESS_KEY_ID'],
:secret_access_key => ENV['AWS_SECRET_ACCESS_KEY']
}
}
I just add: :s3_region => ENV['AWS_REGION'],
to production.rb
then run
heroku config:set AWS_REGION=my_region
Now it upload images properly

Access all nodes in neo4j

On rails console i am trying to call
#invoice = Invoice.all
which returns me some object like
<Neo4j::Traversal::Traverser:0x817382>
but when i tried to loop over the object like
#invoice.each { |t| p t.number }
i got nil,but database contains data for invoice.
Invoice class
class Invoice < Searchable
include Neo4jrb::Paperclip
include LinkableEntity
include HeadsupNotify
enable_optimistic_locking
before_destroy :verify_links, :prepend => true
before_destroy :destroy_invoice_items
property :number, :type => :string
property :currency, :default => Money.default_currency.to_s
property :date, :pay_by_date, :type => :date
property :purchase_order_number
property :settle, :default => false
property :link_1, :link_2, :type => :string
index :number, :type => :fulltext
domain_property :details
money_property :total_cost, :receivable_amount
attr_protected :total_cost, :receivable_amount
attr_accessor :delink_receipt
validates :total_cost, :numericality => {:greater_than_or_equal_to => 0}
validates :receivable_amount, :numericality => {:greater_than_or_equal_to => 0}
validates :date,:number, :customer_id, :event_id, :project_id, :department_id,
:brand_id, :premise_id, :user_id, :currency, :presence => true
validates :link_1, :length => { :maximum => 250 }
validates :link_2, :length => { :maximum => 250 }
validate :number_uniqueness
validate :invoice_items_present
validate :invoice_items_currency
validate :issue_credit_notes_valid
validate :pay_by_date_valid, :unless => "date.nil?"
validate :check_not_linked, :on => :update
has_one(:event).from(Event, :invoices_for_event)
has_one(:project).from(Project, :invoices_for_project)
has_one(:department).from(Department, :invoices_for_department)
has_one(:brand).from(Brand, :invoices_for_brand)
has_one(:premise).from(Premise, :invoices_for_premise)
has_one(:user).to(User)
has_one(:customer).from(Customer, :invoices_for_customer)
alias :party :customer
has_n(:invoice_items).to(InvoiceItem)
has_n(:receipts).from(Receipt, :paid_invoices)
has_n(:issue_credit_notes).from(IssueCreditNote, :credit_notes_for_invoice)
has_one(:invoices_for_settle).to(Settle)
links :receipts, :issue_credit_notes,:invoices_for_settle
has_neo4jrb_attached_file :photo
{:customer => :name, :event => :name, :department => :name, :project => :name, :brand => :name,
:premise => :name, :user => :email}.each do |target, method|
delegate method, :to => target, :prefix => true, :allow_nil => true
end
accepts_id_for :customer, :event, :project, :department, :brand, :premise, :user
accepts_nested_attributes_for :invoice_items, :allow_destroy => true
validates_associated :invoice_items
validates :customer_name, :presence => true, :length => { :maximum => 100 }
validates :event_name, :presence => true, :length => { :maximum => 100 }
validates :premise_name, :presence => true, :length => { :maximum => 100 }
validates :project_name, :presence => true, :length => { :maximum => 100 }
validates :brand_name, :presence => true, :length => { :maximum => 100 }
validates :department_name, :presence => true, :length => { :maximum => 100 }
validates :link_1, :length => { :maximum => 250 }
validates :link_2, :length => { :maximum => 250 }
after_validation :set_total_cost
serialize :methods => :invoice_items
before_validation :delink
Can anyone please help me with this?
Thanks in advance.
I'm not exactly sure of how to do this with Ruby On Rails, but if your Invoice objects (nodes) are in a lucene full text index, you could use a Cypher query to return all Invoices.
Something like:
START invoices=node:Invoices('name: *') RETURN invoices;

Netzke basepack. Need advice with multi uploading fields

Is there any easy way to include the multiupload feature to NetzkeFormView or GridView(AddInForm)?
My current image uloading field with carrierwave is:
{:name => :image_link, :xtype => :displayfield, :display_only => true, :getter => lambda { |r| %Q(<a href='#{r.image.url}'>Download</a>) if r.image.url }},
{:name => :image, :field_label => "Upload image", :xtype => :fileuploadfield, :getter => lambda { |r| "" }, :display_only => true}

S3 photo id issue

model: 1
class PromotionPhoto < ActiveRecord::Base
has_attached_file :photo,
:styles => {
:large => "524x257!",
:xmedium => "435x330!",
:medium => "329x152!",
:thumb => "100x100!"
},
:storage => :s3,
:s3_credentials => "#{RAILS_ROOT}/config/s3.yml",
:path => ":attachment/:id/:style.:extension"
end
model 2:
class PromotionMenuPhoto < ActiveRecord::Base
has_attached_file :photo,
:styles => {
:thumb => "50x50!"
},
:storage => :s3,
:s3_credentials => "#{RAILS_ROOT}/config/s3.yml",
:path => ":attachment/:id/:style.:extension"
end
tables
promotion_photos
id | photo_file_name | photo_content_type | photo_file_size
promotion_menu_photos
id | photo_file_name | photo_content_type | photo_file_size
problem: if i upload promotions photo showing correct. But same photo display promotion_menus also. what is the wrong? can you help me?
You have the same attachment path for both models:
:path => ":attachment/:id/:style.:extension"
In both models attachment name is photo.
Change attachment name or path in one of models.
Here is documentation for paperclip has_attached_file: http://rubydoc.info/gems/paperclip/2.4.5/Paperclip/ClassMethods:has_attached_file

rails3.1 and formtastic 2.0.0.rc2 - undefined method `inputs'

I am using rails 3.1.0.rc3 with formtastic 2.0.0.rc2 and I am getting this error -
undefined method `inputs' for #<ActionView::Helpers::FormBuilder:0x000001059c2fb0>
Here is the block of code
= form_tag '#', :class => 'formtastic' do
= fields_for CustomFields::Field.new, :builder => Formtastic::Helpers::FormHelper.builder do |g|
= g.inputs :name => :attributes do
= g.input :_alias
= g.input :hint
= g.input :text_formatting, :as => 'select', :collection => options_for_text_formatting, :include_blank => false, :wrapper_html => { :style => 'display: none' }
= g.input :target, :as => 'select', :collection => options_for_association_target, :include_blank => false, :wrapper_html => { :style => 'display: none' }
Is this a bug ?
Thanks, Alex
You are trying to use a formtastic method here. When you are actually in a block for Rails's form builder.
You need semantic_form_for and formtastic in your Gemfile to use f.inputs for example..