Reputation: 20445
I have the following tag partial
%span.tag-label
= link_to "#{tag}" , :controller => "searches", :action => "search_tags", :search_type => search_type,
:tag_type => tag_type, :tag =>"#{tag}"
and I pass tags to the partial as collection:
= render "shared/tag_item", :collection => @listing.keyword_list, :as => :tag,
:search_type => "Listing", :tag_type => nil
For some reason, I got this error:
wrong number of arguments (0 for 1)
in my partial.
If I just put plain text on link_to "text"
and :tag =>"text"
then it works.
Why my embedded text in "#{tag}"
doesn't work in this case?
Thank you. Update Show error trace: `endered listings/show.html.haml within layouts/application (148.4ms) Completed 500 Internal Server Error in 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&line=2&column=1">app/views/shared/_tag_item.html.haml
Upvotes: 0
Views: 390
Reputation: 11710
When passing local variables to your partial, you have to pass the render
method the key :locals
.
render "shared/tag_item", :collection => @listing.keyword_list, :as => :tag, :locals => { :search_type => "Listing", :tag_type => nil }
Though I have to admit, I would have expected this to give a NameError and not an ArgumentError. Do a search_type or tag_type method exist somewhere in your code?
Upvotes: 1
Reputation: 14983
Not sure if this will fix your problem, but you don't need to interpolate your tag
variable. You can just write link_to tag
and :tag => tag
.
Upvotes: 0