Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Paperclip image inside link_to => undefined method `symbolize_keys!' for #<Design:0x00000002dfa5f0>

I have the following code:

<% if design.avatar.file? %>
    <%= link_to image_tag design.avatar.url(:thumb), design %>
<% else %>
    <%= link_to image, design %>
<% end%>

And i get this error:

undefined method `symbolize_keys!' for #<Design:0x00000002dfa5f0>

But then, if I remove the design part from first link, leaving code like this:

<% if design.avatar.file? %>
    <%= link_to image_tag design.avatar.url(:thumb) %>
<% else %>
    <%= link_to image, design %>
<% end%>

It works! Obviously with an empty link in the first place, but renders the page.

The image variable is defined in application_helper.rb as follows:

def image
    image = image_tag("image.jpg", :alt => %(No image available), :class => "round")
end

I'm obviously missing something here...

like image 788
mornaner Avatar asked Dec 11 '25 16:12

mornaner


1 Answers

you should at least put parentheses around your inner method call:

<%= link_to image_tag(design.avatar.url(:thumb)), design %>

because ruby interprets design as second argument to image_tag, and image_tag expects a hash there, which it tries to normalize (with symbolize_keys!)

like image 121
Marian Theisen Avatar answered Dec 14 '25 06:12

Marian Theisen