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.
Ead43bcb0202410540a6a7cee5955d46?d=identicon&s=25 Fresh Mix (giga)
on 2009-03-25 21: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
Ead43bcb0202410540a6a7cee5955d46?d=identicon&s=25 Fresh Mix (giga)
on 2009-03-26 12:16
I have this problem only if I run Rails by mongrel_cluster.

./script/server works fine.
0c31801aba0747b84974df56ade208f3?d=identicon&s=25 robdoan (Guest)
on 2009-03-27 12: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 Mix <rails-mailing-l...@andreas-s.net>
40db9e75b3f5899258e3bdc0c9210154?d=identicon&s=25 Conrad Taylor (conradwt)
on 2009-03-27 13:29
(Received via mailing list)
On Fri, Mar 27, 2009 at 2:59 AM, robdoan <quydoantran@gmail.com> 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
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2009-03-27 13:47
(Received via mailing list)
On Mar 27, 12:28 pm, Conrad Taylor <conra...@gmail.com> 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.