2012-04-08 41 views
0

我有以下的标记部分插入文本的link_to Rails中

%span.tag-label 
    = link_to "#{tag}" , :controller => "searches", :action => "search_tags", :search_type => search_type, 
    :tag_type => tag_type, :tag =>"#{tag}" 

和我通过标记部分为集合:

= render "shared/tag_item", :collection => @listing.keyword_list, :as => :tag, 
:search_type => "Listing", :tag_type => nil 

出于某种原因,我得到这个错误:

wrong number of arguments (0 for 1) 

在我的部分。

如果我只是把纯文本放在link_to "text"tag =>"text"那么它就可以工作。 为什么我的嵌入文本"#{tag}"在这种情况下不起作用?

谢谢。 更新显示错误跟踪: `endered列表/布局内show.html.haml /应用(148.4ms) 完成500内部服务器错误在232ms

ActionView::Template::Error (wrong number of arguments (0 for 1)): 
    1: %span.tag-label 
    2: = link_to "#{tag.to_s}" , :controller => "searches", :action => "search_tags", :search_type => search_type, 
    3: :tag_type => tag_type, :tag =>"#{tag.to_s}" 
    <a href="txmt://open?url=file:///Users/app/views/shared/_tag_item.html.haml&amp;line=2&amp;column=1">app/views/shared/_tag_item.html.haml 
+0

显示错误发生位置的错误跟踪。 – Zabba 2012-04-08 02:28:33

+0

确保'link_to“#{tag}”,''实际上'link_to“#{tag}”,' – 2012-04-08 02:47:46

+0

如果您只输出'url_for(:controller =>“searching”,:action =>“search_tags”,: search_type => search_type, :tag_type => tag_type,:tag =>“#{tag}”)'而不是'link_to..'按预期输出吗? – 2012-04-08 03:38:11

回答

1

将局部变量传递给你的局部变量时,必须通过render方法键:locals

render "shared/tag_item", :collection => @listing.keyword_list, :as => :tag, :locals => { :search_type => "Listing", :tag_type => nil } 

虽然我不得不承认,我本来期望这给予NameError而不是一个ArgumentError。 search_type或tag_type方法是否存在于代码中的某处?

0

不知道这是否会解决您的问题,但你不需要插入你的变量tag。你可以写link_to tag:tag => tag

+1

感谢格兰丹,但它没有奏效。 – AdamNYC 2012-04-08 02:37:23