- Previous thread: how to read password from keyboard
- Next thread: - .all?{} and - .any?{} Behavior
- Threads sorted by date: ruby-talk 201007
Hi,
I'm using the paperclip plugin for one of my rails app, but my problem
is pure Ruby. I'm not good enough with Ruby and lambdas so I need your
advice.
Here is the code I am trying to make work:
class Asset < ActiveRecord::Base
has-attached-file :data, :styles = :theora =[:video-converter] : []}}]
}
end
What fails is the lambda, because in Paperclip behind the scenes this is
what happens:
@var = style.processors.inject(something) do |file, processor|
...
end
style.processors has received the lambda defined earlier.
And I get the following error message:
NoMethodError (undefined method `inject' for #)
So how can I fix it, and after that which book or resources can I read
to get proficient in such dynamic coding practice? Currently in use
blocks all the time ([array].each { ...}) without really mastering them.
Thanks for your support
I'm using the paperclip plugin for one of my rails app, but my problem
is pure Ruby. I'm not good enough with Ruby and lambdas so I need your
advice.
Here is the code I am trying to make work:
class Asset < ActiveRecord::Base
has-attached-file :data, :styles = :theora =[:video-converter] : []}}]
}
end
What fails is the lambda, because in Paperclip behind the scenes this is
what happens:
@var = style.processors.inject(something) do |file, processor|
...
end
style.processors has received the lambda defined earlier.
And I get the following error message:
NoMethodError (undefined method `inject' for #)
So how can I fix it, and after that which book or resources can I read
to get proficient in such dynamic coding practice? Currently in use
blocks all the time ([array].each { ...}) without really mastering them.
Thanks for your support
On Thu, Jul 29, 2010 at 3:38 PM, Fernando Perez wrote:
You have an extra } before ]. I'm assuming that wasn't part of your
actual script, because then you'd get a syntax error.
It looks like style.processors is itself a proc instead of an
enumerable. Try to find where it was assigned and make sure you pass
the proc inside of an array.
You have an extra } before ]. I'm assuming that wasn't part of your
actual script, because then you'd get a syntax error.
It looks like style.processors is itself a proc instead of an
enumerable. Try to find where it was assigned and make sure you pass
the proc inside of an array.
On Thu, Jul 29, 2010 at 10:38 PM, Fernando Perez wrote:
I have no idea about paperclip, but looking at the above snippets
style.processor should be an Enumerable (which is where inject is
defined), for example an array. Given that the key in the hash is
:processors (in plural) I would assume that the value should be an
array of processors. So, even if you only have one lambda, can you try
this:
class Asset < ActiveRecord::Base
has-attached-file :data, :styles = :theora =? [:video-converter] : []}]}]
}
Jesus.
I have no idea about paperclip, but looking at the above snippets
style.processor should be an Enumerable (which is where inject is
defined), for example an array. Given that the key in the hash is
:processors (in plural) I would assume that the value should be an
array of processors. So, even if you only have one lambda, can you try
this:
class Asset < ActiveRecord::Base
has-attached-file :data, :styles = :theora =? [:video-converter] : []}]}]
}
Jesus.
Yes style.processors is expected to be an array
Unfortunately it doesn't work, as when the lambda gets executed, the "a"
object it receives is not the not it expects: "wrong constant name
passed".
On Fri, Jul 30, 2010 at 5:40 AM, Fernando Perez wrote:
I suspect that you would get better answers on the rails forum since
paperclip is better known there than in the general Ruby community.
but..
First, the :processors option isn't supposed to be part of the :style hash
has-attached-file :date,
:styles = :processors = # something goes here
]
Now it appears you are trying to use a feature of paperclip which
doesn't seem to be documented, normally the value for the :processors
option is just an array of symbols which are converted to an instance
of a subclass of Paperclip::Processor. But from reading the code it
appears that you can also do:
class Asset < ActiveRecord::Base
has-attached-file :date,
:styles = :processors =instance of the Asset model
asset.video? ? [:video-converter] : []
}
end
I'd probably refactor this a bit:
class Asset < ActiveRecord::Base
has-attached-file :date,
:styles = :processors =asset.processors }
def processors
self.video? ? [:video-converter] : []
end
end
I've tested none of this so take it with the appropriate grain of salt.
Blog: http://talklikeaduck.denhaven2.com/
Github: http://github.com/rubyredrick
Twitter: @RickDeNatale
WWR: http://www.workingwithrails.com/person/9021-rick-denatale
LinkedIn: http://www.linkedin.com/in/rickdenatale
I suspect that you would get better answers on the rails forum since
paperclip is better known there than in the general Ruby community.
but..
First, the :processors option isn't supposed to be part of the :style hash
has-attached-file :date,
:styles = :processors = # something goes here
]
Now it appears you are trying to use a feature of paperclip which
doesn't seem to be documented, normally the value for the :processors
option is just an array of symbols which are converted to an instance
of a subclass of Paperclip::Processor. But from reading the code it
appears that you can also do:
class Asset < ActiveRecord::Base
has-attached-file :date,
:styles = :processors =instance of the Asset model
asset.video? ? [:video-converter] : []
}
end
I'd probably refactor this a bit:
class Asset < ActiveRecord::Base
has-attached-file :date,
:styles = :processors =asset.processors }
def processors
self.video? ? [:video-converter] : []
end
end
I've tested none of this so take it with the appropriate grain of salt.
Blog: http://talklikeaduck.denhaven2.com/
Github: http://github.com/rubyredrick
Twitter: @RickDeNatale
WWR: http://www.workingwithrails.com/person/9021-rick-denatale
LinkedIn: http://www.linkedin.com/in/rickdenatale
Hi Rick,
Yes it can. It's undocumented, I have tried and it works, but only if I
hardcode the processors array. Using the lambda doesn't work for
processors defined for specific styles.
I'll read the pickaxe to improve my ruby skills.
Yes it can. It's undocumented, I have tried and it works, but only if I
hardcode the processors array. Using the lambda doesn't work for
processors defined for specific styles.
I'll read the pickaxe to improve my ruby skills.
Related Threads
- PATCH 06/13 - ath9k_htc: Revamp CONF_IDLE handling - linux-wireless
- PHPUnit integration with Linux Server - netbeans-php-users
- cumulative counts over time - hadoop-mapreduce-user
- Xen-users - How to make bridge with no IP - xen-users
- Re: Xen-users - pygrub error booting iso - xen-users
- Forcing Samba to recognize 15 char password - samba-technical
- How do I move a message between 2 queues? - qpid-users
- Re: ports/148026: PATCH - security/py-twistedConch: missing run depedency for py-asn1 - freebsd-python
- curl library bug - curl-library
- zfs-discuss - Resilvering onto a spare - degraded because of read and cksum errors - opensolaris-zfs
Related Lists
- centos-devel
- centos-docs
- centos-general
- centos-virt
- curl-library
- curl-users
- emc-developers
- emc-users
- gentoo-amd64
- gentoo-desktop
- gentoo-dev
- gentoo-user
- haskell-beginners
- haskell-cafe
- haskell-general
- libssh2-devel
- lua
- microformats-discuss
- openmoko
- openvz-users
- red5
- rockbox-dev
- ruby-talk
- trac-dev
- trac-users
- veritas-bu
- vim-dev
- vim-mac
- vim-use
- webkit-dev
- webkit-help
- wine-devel
- wine-users
- wxwidgets-dev
- wxwidgets-users
- xfce
- xmleditor-support
- xorg-devel
- xorg-driver-ati
- xorg-general
- xorg-xcb
- xorg-xdg