[英]Passing params in a helper
I have, on my Miniature model view page the following code 我的微型模型视图页面上有以下代码
<%= content_setmini_links_with_quantity(@miniature) %>
It refers to this miniatures_helper method 它引用了这个miniatures_helper方法
def content_setmini_links_with_quantity(miniature)
miniature.reverse_contents.map{|content| content_setmini_link_with_quantity(content)}.join(' ').html_safe
end
Which in turn references this miniatures_helper method 依次引用此miniatures_helper方法
def content_setmini_link_with_quantity(content)
string = (tag "td"), (link_to top_pic(content.setmini_id), content.setmini), (link_to content.setmini.name, content.setmini)
string << " x#{content.quantity}" if content.quantity.present?
return string
end
This is supposed to reference the final miniatures_helper method 这应该参考最终的miniatures_helper方法
def top_pic
@miniature = Miniature.find(params[:setmini_id])
if @miniature.collections.first.photo != nil
image_tag(@miniature.collections.first.photo.url(:icon), :retina => true, :class => "curvediconminiset")
else
image_tag("https://system/stock/blank.gif", :retina => true, :class => "curvediconminiset")
end
end
but I can't work out how to call top_pic correctly. 但我不知道如何正确调用top_pic。
As far as I can see in content_setmini_link_with_quantity(content)
the only param available is content. 据我在
content_setmini_link_with_quantity(content)
看到的,唯一可用的参数是content。 Content.setmini_id
is the param I want to use to find the @miniature
to display but I can't get it to work. Content.setmini_id
是我要用于查找要显示的@miniature
,但无法正常工作。
Any help much appreciated. 任何帮助,不胜感激。
You are calling 你在打电话
top_pic(content.setmini_id)
But your top_pic
method definition does not have a parameter defined. 但是您的
top_pic
方法定义没有定义参数。
Change the definition and first line of top_pic
to 将
top_pic
的定义和第一行top_pic
为
def top_pic(setmini_id)
@miniature = Miniature.find(setmini_id)
and forget about using params
in a helper. 忘了在助手中使用
params
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.