The problem variable here is @item_class. It’s not passing as an extra
parameter.
I have in my partial
<%= @item_class.name %> #Just to make sure @item_class is not null
<%= link_to_if someCondition, ‘myLink’, :action=>:myLinkAction, :id =>
@item,:item_class=> @item_class.name %>
the above renders
Photo
myLink
which is missing the extra parameter Photo.
Why don’t I see
myLink
if I add a string like ‘wibble’
<%= link_to_if someCondition, ‘myLink’, :action=>:myLinkAction, :id =>
@item,:item_class=> @item_class.name, :extra=>‘wibble’ %>
I get
Photo
myLink
Ok, if I switch it to
<%= @item_class.name %>
<%= link_to_if someCondition, ‘myLink’, :action=>:myLinkAction, :id =>
@item,:extras=> @item_class.name, :item_class=>‘wibble’ %>
I get
Photo
myLink
What’s the problem with using a parameter having a same name as a
variable? I didn’t see this issue until I went to 1.2.2 from 1.1.6.
I REALLY appreciate the help, it’s been about 2 weeks I’ve been
wrestling with this.
if I add a string like ‘wibble’
<%= link_to_if someCondition, ‘myLink’, :action=>:myLinkAction, :id =>
@item,:item_class=> @item_class.name, :extra=>‘wibble’ %>
if you enter :item_class=> ‘wibble’ what do you get?
Yottameter wrote:
Ok, if I switch it to
<%= @item_class.name %>
<%= link_to_if someCondition, ‘myLink’, :action=>:myLinkAction, :id =>
@item,:extras=> @item_class.name, :item_class=>‘wibble’ %>
Yeah, seems the link_to_if helper thinks your trying to assign a value
to the :item_class symbol which already exists, not pass it a param.
Have you thought about renaming your param?
You could override the link_to_if helper and see what it’s spitting out:
def link_to_if(condition, name, options = {}, html_options = {},
*parameters_for_method_reference, &block)
return *parameters_for_method_reference
end
no clue if that’ll work though…
good luck.
One other note, this only happens with named routes. item_class is
assigned in the named route, I get the results above. If I manually
type it into the url, it’s fine.
I’ll try your suggestion. Thanks again for the help.
parameters_for_method_reference should probably be nil.
What is the route for this action? What does
url_for(:action=>:myLinkAction, :id =>
@item, :extras=> @item_class.name, :item_class=>‘wibble’) generate?
Ok if I return the various arguments passed in, I see:
condition: true
name: myLink
options:item_classwibbleextrasPhotoactionmyLinkActionid
html_options: NULL
*parameters_for_method_reference: NULL
No block supplied, so didn’t check that.
What were you expecting for *parameters for method_reference?
The url_for generates:
/item/myLinkAction?extras=Photo