Forum: Ruby on Rails View link not working....

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Yottameter (Guest)
on 2007-03-11 03:32
(Received via mailing list)
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
<a href="/item/myLinkAction/10">myLink</a>

which is missing the extra parameter Photo.


Why don't I see

<a href="/item/myLinkAction/10?item_class=Photo">myLink</a>


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
<a href="/item/myLinkAction/10?extra=wibble">myLink</a>
Dave C. (Guest)
on 2007-03-11 18:21
> 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 (Guest)
on 2007-03-11 23:52
(Received via mailing list)
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
<a href="/item/myLinkAction/10?extras=Photo">myLink</a>

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.
Dave C. (Guest)
on 2007-03-12 00:10
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.
Yottameter (Guest)
on 2007-03-12 01:03
(Received via mailing list)
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.
Yottameter (Guest)
on 2007-03-12 03:28
(Received via mailing list)
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?
Eden L. (Guest)
on 2007-03-12 05:01
(Received via mailing list)
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?
Yottameter (Guest)
on 2007-03-12 05:05
(Received via mailing list)
The url_for generates:

/item/myLinkAction?extras=Photo
This topic is locked and can not be replied to.