Forum: Ruby on Rails help with link_to_if, I can't make it work...

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.
73606b1d1042de19056f3d59492b652f?d=identicon&s=25 charlie bowman (Guest)
on 2006-01-04 02:36
For the life of me I can't get it to work.  Here is an example of my
syntax.  I'm trying to make comment.name a link to comment.web_site only
if there is a comment.web_site.  Can someone please help?

<%= link_to_if(comment.web_site.length > 0, comment.name,
comment.web_site {"class"  => "comment_by"})  %>
73606b1d1042de19056f3d59492b652f?d=identicon&s=25 charlie bowman (Guest)
on 2006-01-04 05:05
has anyone else tried to use link_to_if?


charlie bowman wrote:
> For the life of me I can't get it to work.  Here is an example of my
> syntax.  I'm trying to make comment.name a link to comment.web_site only
> if there is a comment.web_site.  Can someone please help?
>
> <%= link_to_if(comment.web_site.length > 0, comment.name,
> comment.web_site {"class"  => "comment_by"})  %>
F66cc63471b71843dba49db8e2b3771d?d=identicon&s=25 Lieven De keyzer (lieven)
on 2006-01-04 13:36
charlie bowman wrote:
> For the life of me I can't get it to work.  Here is an example of my
> syntax.  I'm trying to make comment.name a link to comment.web_site only
> if there is a comment.web_site.  Can someone please help?
>
> <%= link_to_if(comment.web_site.length > 0, comment.name,
> comment.web_site {"class"  => "comment_by"})  %>

Do you get errors? Other resulst as the ones you expect?
73606b1d1042de19056f3d59492b652f?d=identicon&s=25 Charlie Bowman (beachguy82)
on 2006-01-04 13:41
yes, here they are.

ActionView::TemplateError (compile error
script/../config/../app/views/journal/view.rhtml:21: syntax error
comment.web_site {"class"  => "comment_by"})  ).to_s); _erbout.concat
"\r\n"
                             ^) on line #21 of
app/views/journal/view.rhtml:
18:                     <span class="post_date"> commented...</span><br
/>
19:                     <div class="comment"><%=
strip_tags(comment.comment) %></div><br />
20:                     <%= link_to_if(comment.web_site.length > 0,
comment.name,
21: comment.web_site {"class"  => "comment_by"})  %>
22:             <% end %>
23: <h3>Comment Form</h3>
24: <%= start_form_tag(:action  => "save_comment", :id  => @post.id) %>





Lieven De Keyzer wrote:
> charlie bowman wrote:
>> For the life of me I can't get it to work.  Here is an example of my
>> syntax.  I'm trying to make comment.name a link to comment.web_site only
>> if there is a comment.web_site.  Can someone please help?
>>
>> <%= link_to_if(comment.web_site.length > 0, comment.name,
>> comment.web_site {"class"  => "comment_by"})  %>
>
> Do you get errors? Other resulst as the ones you expect?
F66cc63471b71843dba49db8e2b3771d?d=identicon&s=25 Lieven De keyzer (lieven)
on 2006-01-04 13:44
charlie bowman wrote:
> yes, here they are.
>
> ActionView::TemplateError (compile error
> script/../config/../app/views/journal/view.rhtml:21: syntax error
> comment.web_site {"class"  => "comment_by"})  ).to_s); _erbout.concat
> "\r\n"
>                              ^) on line #21 of
> app/views/journal/view.rhtml:
> 18:                     <span class="post_date"> commented...</span><br
> />
> 19:                     <div class="comment"><%=
> strip_tags(comment.comment) %></div><br />
> 20:                     <%= link_to_if(comment.web_site.length > 0,
> comment.name,
> 21: comment.web_site {"class"  => "comment_by"})  %>
> 22:             <% end %>
> 23: <h3>Comment Form</h3>
> 24: <%= start_form_tag(:action  => "save_comment", :id  => @post.id) %>
>
>
>
>
>
> Lieven De Keyzer wrote:
>> charlie bowman wrote:
>>> For the life of me I can't get it to work.  Here is an example of my
>>> syntax.  I'm trying to make comment.name a link to comment.web_site only
>>> if there is a comment.web_site.  Can someone please help?
>>>
>>> <%= link_to_if(comment.web_site.length > 0, comment.name,
>>> comment.web_site {"class"  => "comment_by"})  %>
>>
>> Do you get errors? Other resulst as the ones you expect?

Well, it seems like you've forgotten a comma.

Try:

<%= link_to_if(comment.web_site.length > 0, comment.name,
               comment.web_site ----->,<------ {"class"  =>
"comment_by"})  %>
73606b1d1042de19056f3d59492b652f?d=identicon&s=25 Charlie Bowman (beachguy82)
on 2006-01-04 23:21
That worked like a charm! Thanks for the help!


>>
>> Lieven De Keyzer wrote:

> Try:
>
> <%= link_to_if(comment.web_site.length > 0, comment.name,
>                comment.web_site ----->,<------ {"class"  =>
> "comment_by"})  %>
This topic is locked and can not be replied to.