# View link not working

**URL:** <https://www.ruby-forum.com/t/view-link-not-working/88440>\
**Category:** Rails\
**Created:** [March 11, 2007, 2:32am UTC](https://www.ruby-forum.com/t/view-link-not-working/88440 "2007-03-11T02:32:42Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![yottameter](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/df705f/32.png) [@yottameter](https://www.ruby-forum.com/u/yottameter)\
**Post date:** [March 11, 2007, 2:32am UTC](https://www.ruby-forum.com/t/view-link-not-working/88440/1 "2007-03-11T02:32:42Z")

</div>

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](https://www.ruby-forum.com/item/myLinkAction/10)

which is missing the extra parameter Photo.

Why don’t I see

[myLink](https://www.ruby-forum.com/item/myLinkAction/10?item_class=Photo)

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](https://www.ruby-forum.com/item/myLinkAction/10?extra=wibble)

---

<div class="post-metadata">

**Author:** ![yottameter](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/df705f/32.png) [@yottameter](https://www.ruby-forum.com/u/yottameter)\
**Post date:** [March 11, 2007, 10:52pm UTC](https://www.ruby-forum.com/t/view-link-not-working/88440/2 "2007-03-11T22:52:01Z")

</div>

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](https://www.ruby-forum.com/item/myLinkAction/10?extras=Photo)

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.

---

<div class="post-metadata">

**Author:** ![yottameter](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/df705f/32.png) [@yottameter](https://www.ruby-forum.com/u/yottameter)\
**Post date:** [March 11, 2007, 5:21pm UTC](https://www.ruby-forum.com/t/view-link-not-working/88440/3 "2007-03-11T17:21:28Z")

</div>

> 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?

---

<div class="post-metadata">

**Author:** ![yottameter](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/df705f/32.png) [@yottameter](https://www.ruby-forum.com/u/yottameter)\
**Post date:** [March 11, 2007, 11:10pm UTC](https://www.ruby-forum.com/t/view-link-not-working/88440/4 "2007-03-11T23:10:04Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![yottameter](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/df705f/32.png) [@yottameter](https://www.ruby-forum.com/u/yottameter)\
**Post date:** [March 12, 2007, 12:03am UTC](https://www.ruby-forum.com/t/view-link-not-working/88440/5 "2007-03-12T00:03:08Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![yottameter](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/df705f/32.png) [@yottameter](https://www.ruby-forum.com/u/yottameter)\
**Post date:** [March 12, 2007, 4:01am UTC](https://www.ruby-forum.com/t/view-link-not-working/88440/6 "2007-03-12T04:01:29Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![yottameter](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/df705f/32.png) [@yottameter](https://www.ruby-forum.com/u/yottameter)\
**Post date:** [March 12, 2007, 2:28am UTC](https://www.ruby-forum.com/t/view-link-not-working/88440/7 "2007-03-12T02:28:23Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![yottameter](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/df705f/32.png) [@yottameter](https://www.ruby-forum.com/u/yottameter)\
**Post date:** [March 12, 2007, 4:05am UTC](https://www.ruby-forum.com/t/view-link-not-working/88440/8 "2007-03-12T04:05:29Z")

</div>

The url\_for generates:

/item/myLinkAction?extras=Photo
