开发者

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

开发者 https://www.devze.com 2023-04-09 05:35 出处:网络
I have the following code: <% if design.avatar.file? %> <%= link_to image_tag design.avatar.url(:thumb), design %>

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) %&g开发者_JAVA技巧t;
<% 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...


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!)

0

精彩评论

暂无评论...
验证码 换一张
取 消