Forum: Ruby on Rails What wrong?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Fresh M. (Guest)
on 2009-03-25 22:31
I can't make this work:

http://groups.google.com/group/paperclip-plugin/br...


Where I have to place this code?

Paperclip::Attachment.interpolations[:random_key] = lambda do |
attachment, style|
   attachment.instance.random_key
end

I always get: undefined method `random_key'


Rais 2.3.2 and paperclip installed by gem
Fresh M. (Guest)
on 2009-03-26 13:16
I have this problem only if I run Rails by mongrel_cluster.

./script/server works fine.
robdoan (Guest)
on 2009-03-27 13:50
(Received via mailing list)
As I remember u can not use lambda do do |abc |
end
U must use : lambda {| abc|   }


On Mar 26, 6:16 pm, Fresh M. <removed_email_address@domain.invalid>
Conrad T. (Guest)
on 2009-03-27 14:29
(Received via mailing list)
On Fri, Mar 27, 2009 at 2:59 AM, robdoan <removed_email_address@domain.invalid> 
wrote:

>
> As I remember u can not use lambda do do |abc |
> end
> U must use : lambda {| abc|   }
>
>
lambda do |abc|
...
end

is equivalent to

lambda { |abc| ... }

Thus, they are both legal in Ruby 1.8 and 1.9.

-Conrad
Frederick C. (Guest)
on 2009-03-27 14:47
(Received via mailing list)
On Mar 27, 12:28 pm, Conrad T. <removed_email_address@domain.invalid> wrote:
> is equivalent to
>
> lambda { |abc| ... }
>
> Thus, they are both legal in Ruby 1.8 and 1.9.
>

{} binds more tightly than do..end so you do sometimes need to use ()
to disambiguate, eg

named_scope :foo, lambda { ... }

is ok

but

named_scope :foo, lambda do
...
end

isn't because ruby thinks that this block is for named_scope, not
lambda.

named_scope(:foo, lambda do
...
end)

makes it clear to ruby what to do.

Fred
This topic is locked and can not be replied to.