# Help with link\_to\_if, I can't make it work

**URL:** <https://www.ruby-forum.com/t/help-with-link-to-if-i-cant-make-it-work/56146>\
**Category:** Rails\
**Created:** [January 4, 2006, 2:36am UTC](https://www.ruby-forum.com/t/help-with-link-to-if-i-cant-make-it-work/56146 "2006-01-04T02:36:30Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![charlie\_bowman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/b5e925/32.png) [@charlie\_bowman](https://www.ruby-forum.com/u/charlie_bowman)\
**Post date:** [January 4, 2006, 2:36am UTC](https://www.ruby-forum.com/t/help-with-link-to-if-i-cant-make-it-work/56146/1 "2006-01-04T02:36:30Z")

</div>

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”}) %\>

---

<div class="post-metadata">

**Author:** ![charlie\_bowman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/b5e925/32.png) [@charlie\_bowman](https://www.ruby-forum.com/u/charlie_bowman)\
**Post date:** [January 4, 2006, 5:05am UTC](https://www.ruby-forum.com/t/help-with-link-to-if-i-cant-make-it-work/56146/2 "2006-01-04T05:05:39Z")

</div>

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”}) %\>

---

<div class="post-metadata">

**Author:** ![charlie\_bowman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/b5e925/32.png) [@charlie\_bowman](https://www.ruby-forum.com/u/charlie_bowman)\
**Post date:** [January 4, 2006, 1:41pm UTC](https://www.ruby-forum.com/t/help-with-link-to-if-i-cant-make-it-work/56146/3 "2006-01-04T13:41:57Z")

</div>

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: commented…  
  
19:

\<%=  
strip\_tags(comment.comment) %\>
  
  
20: \<%= link\_to\_if(comment.web\_site.length \> 0,  
comment.name,  
21: comment.web\_site {“class” =\> “comment\_by”}) %\>  
22: \<% end %\>  
23: 
### Comment Form
  
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?

---

<div class="post-metadata">

**Author:** ![charlie\_bowman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/b5e925/32.png) [@charlie\_bowman](https://www.ruby-forum.com/u/charlie_bowman)\
**Post date:** [January 4, 2006, 1:44pm UTC](https://www.ruby-forum.com/t/help-with-link-to-if-i-cant-make-it-work/56146/4 "2006-01-04T13:44:19Z")

</div>

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: commented…  
>   
> 19:
> 
> \<%=  
> strip\_tags(comment.comment) %\>
>   
>   
> 20: \<%= link\_to\_if(comment.web\_site.length \> 0,  
> comment.name,  
> 21: comment.web\_site {“class” =\> “comment\_by”}) %\>  
> 22: \<% end %\>  
> 23: 
> ### Comment Form
>   
> 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”}) %\>

---

<div class="post-metadata">

**Author:** ![charlie\_bowman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/b5e925/32.png) [@charlie\_bowman](https://www.ruby-forum.com/u/charlie_bowman)\
**Post date:** [January 4, 2006, 1:36pm UTC](https://www.ruby-forum.com/t/help-with-link-to-if-i-cant-make-it-work/56146/5 "2006-01-04T13:36:21Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![charlie\_bowman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/b5e925/32.png) [@charlie\_bowman](https://www.ruby-forum.com/u/charlie_bowman)\
**Post date:** [January 4, 2006, 11:21pm UTC](https://www.ruby-forum.com/t/help-with-link-to-if-i-cant-make-it-work/56146/6 "2006-01-04T23:21:24Z")

</div>

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”}) %\>
