small medium large xlarge

11 Aug 2008, 09:50
Tan YL (19 posts)


need some help again.

i want to insert ruby code into a string like this: <%= image_tag(“/image/groceries/<%=h %>.jpg”, :class =>

how do i call the model in this case?

11 Aug 2008, 10:14
Sam Ruby (634 posts)
<%= image_tag(”/image/groceries/#{h}.jpg”, :class => ...

In beta 1.3, see the description for expression interpolation on page 650.

11 Aug 2008, 10:20
Tan YL (19 posts)

thanks. btw which is more preferable or #{h}

11 Aug 2008, 10:44
Sam Ruby (634 posts)

Expression interpolation calls @to_s@ for you, so that’s not necessary in this case.

The @h@ function does something different, it escapes characters which might be mistaken for markup. id’s are typically numbers, so such a function is not required here.

If you are like me and need to establish and ingrain in habits in order to avoid careless mistakes, I would actually suggest:


If you are the type that feels confident that you know what you are doing, you might prefer the simpler:


And somebody who really knows what they were doing would use named routes instead (page 417 in beta 1.3).

You must be logged in to comment