# What wrong?

**URL:** <https://www.ruby-forum.com/t/what-wrong/163885>\
**Category:** Rails\
**Created:** [March 25, 2009, 9:31pm UTC](https://www.ruby-forum.com/t/what-wrong/163885 "2009-03-25T21:31:40Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![giga](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/b9bd4f/32.png) [@giga](https://www.ruby-forum.com/u/giga)\
**Post date:** [March 25, 2009, 9:31pm UTC](https://www.ruby-forum.com/t/what-wrong/163885/1 "2009-03-25T21:31:40Z")

</div>

I can’t make this work:

[http://groups.google.com/group/paperclip-plugin/browse\_thread/thread/c8f58f0a4ef45d20/95e66f07c5722d96?lnk=gst&q=rename#95e66f07c5722d96](http://groups.google.com/group/paperclip-plugin/browse_thread/thread/c8f58f0a4ef45d20/95e66f07c5722d96?lnk=gst&q=rename#95e66f07c5722d96)

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

---

<div class="post-metadata">

**Author:** ![giga](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/b9bd4f/32.png) [@giga](https://www.ruby-forum.com/u/giga)\
**Post date:** [March 26, 2009, 12:16pm UTC](https://www.ruby-forum.com/t/what-wrong/163885/2 "2009-03-26T12:16:54Z")

</div>

I have this problem only if I run Rails by mongrel\_cluster.

./script/server works fine.

---

<div class="post-metadata">

**Author:** ![giga](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/b9bd4f/32.png) [@giga](https://www.ruby-forum.com/u/giga)\
**Post date:** [March 27, 2009, 12:50pm UTC](https://www.ruby-forum.com/t/what-wrong/163885/3 "2009-03-27T12:50:31Z")

</div>

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](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![giga](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/b9bd4f/32.png) [@giga](https://www.ruby-forum.com/u/giga)\
**Post date:** [March 27, 2009, 1:29pm UTC](https://www.ruby-forum.com/t/what-wrong/163885/4 "2009-03-27T13:29:43Z")

</div>

On Fri, Mar 27, 2009 at 2:59 AM, robdoan [removed\_email\_address@domain.invalid](mailto: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

---

<div class="post-metadata">

**Author:** ![giga](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/b9bd4f/32.png) [@giga](https://www.ruby-forum.com/u/giga)\
**Post date:** [March 27, 2009, 1:47pm UTC](https://www.ruby-forum.com/t/what-wrong/163885/5 "2009-03-27T13:47:54Z")

</div>

On Mar 27, 12:28 pm, Conrad T. [removed\_email\_address@domain.invalid](mailto: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
