# Auto\_link is not working

**URL:** <https://www.ruby-forum.com/t/auto-link-is-not-working/144107>\
**Category:** Rails\
**Created:** [July 25, 2008, 1:22pm UTC](https://www.ruby-forum.com/t/auto-link-is-not-working/144107 "2008-07-25T13:22:22Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sunfish](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/96bed5/32.png) [@sunfish](https://www.ruby-forum.com/u/sunfish)\
**Post date:** [July 25, 2008, 1:22pm UTC](https://www.ruby-forum.com/t/auto-link-is-not-working/144107/1 "2008-07-25T13:22:22Z")

</div>

Hi,  
In one of my project I am using auto\_link function for providing link to  
text.  
but when I am using it with truncate it is not working it gives  
following error

code:- \<%=auto\_link truncate(group\_user.group.description,200)%\>

error:-You have a nil object when you didn’t expect it!  
You might have expected an instance of Array.  
The error occurred while evaluating nil.+

Please anybody can able to solve my problem?

---

<div class="post-metadata">

**Author:** ![sunfish](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/96bed5/32.png) [@sunfish](https://www.ruby-forum.com/u/sunfish)\
**Post date:** [July 25, 2008, 2:30pm UTC](https://www.ruby-forum.com/t/auto-link-is-not-working/144107/2 "2008-07-25T14:30:50Z")

</div>

Please paste the full application trace. I guess you are getting an  
unexpected nil when you are determining description of the group. More  
specifically, you are trying to concatenate(+) something with someother  
thing and the something is in nil at some instance 😛  
auto\_link and truncate can handle nil arguments.  
Cheers,  
Ganesh G.  
SageWork([http://sagework.com](http://sagework.com)) Simplify IT

On Fri, Jul 25, 2008 at 5:22 PM, Sunny B. \<

---

<div class="post-metadata">

**Author:** ![sunfish](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/96bed5/32.png) [@sunfish](https://www.ruby-forum.com/u/sunfish)\
**Post date:** [July 25, 2008, 2:54pm UTC](https://www.ruby-forum.com/t/auto-link-is-not-working/144107/3 "2008-07-25T14:54:19Z")

</div>

Ganesh G. wrote:

> Please paste the full application trace. I guess you are getting an  
> unexpected nil when you are determining description of the group. More  
> specifically, you are trying to concatenate(+) something with someother  
> thing and the something is in nil at some instance 😛  
> auto\_link and truncate can handle nil arguments.  
> Cheers,  
> Ganesh G.  
> SageWork([http://sagework.com](http://sagework.com)) Simplify IT
> 
> On Fri, Jul 25, 2008 at 5:22 PM, Sunny B. \<

d:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action\_view/helpers/text\_helper.rb:388:in  
`auto_link_urls' d:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/multibyte/chars.rb:61:in `gsub’  
d:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active\_support/multibyte/chars.rb:61:in  
`gsub' d:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_view/helpers/text_helper.rb:383:in `auto\_link\_urls’  
d:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action\_view/helpers/text\_helper.rb:181:in  
`auto_link' #{RAILS_ROOT}/app/views/groups/list.rhtml:48:in `\_run\_rhtml\_47app47views47groups47list46rhtml’  
#{RAILS\_ROOT}/app/views/groups/list.rhtml:41:in `each' #{RAILS_ROOT}/app/views/groups/list.rhtml:41:in `\_run\_rhtml\_47app47views47groups47list46rhtml’  
d:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action\_view/base.rb:326:in  
`send' d:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_view/base.rb:326:in `compile\_and\_render\_template’  
d:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action\_view/base.rb:301:in  
`render_template' d:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_view/base.rb:260:in `render\_file’  
d:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action\_controller/base.rb:806:in  
`render_file' d:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/base.rb:711:in `render\_with\_no\_layout’  
d:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action\_controller/layout.rb:247:in  
`render_without_benchmark' d:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/benchmarking.rb:50:in `render’  
d:/ruby/lib/ruby/1.8/benchmark.rb:293:in `measure' d:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/benchmarking.rb:50:in `render’  
d:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action\_controller/base.rb:1096:in  
`perform_action_without_filters' d:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/filters.rb:632:in `call\_filter’  
d:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action\_controller/filters.rb:634:in  
`call_filter' d:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/filters.rb:638:in `call\_filter’  
d:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action\_controller/filters.rb:438:in  
`call' d:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/filters.rb:637:in `call\_filter’  
d:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action\_controller/filters.rb:638:in  
`call_filter' d:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/filters.rb:449:in `call’  
d:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action\_controller/filters.rb:637:in  
`call_filter' d:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/filters.rb:619:in `perform\_action\_without\_benchmark’  
d:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action\_controller/benchmarking.rb:66:in  
`perform_action_without_rescue' d:/ruby/lib/ruby/1.8/benchmark.rb:293:in `measure’  
d:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action\_controller/benchmarking.rb:66:in  
`perform_action_without_rescue' d:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/rescue.rb:83:in `perform\_action’  
d:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action\_controller/base.rb:430:in  
`send' d:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/base.rb:430:in `process\_without\_filters’  
d:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action\_controller/filters.rb:624:in  
`process_without_session_management_support' d:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/session_management.rb:114:in `process’  
d:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action\_controller/base.rb:330:in  
`process' d:/ruby/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/dispatcher.rb:41:in `dispatch’  
d:/ruby/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/webrick\_server.rb:113:in  
`handle_dispatch' d:/ruby/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/webrick_server.rb:79:in `service’  
d:/ruby/lib/ruby/1.8/webrick/httpserver.rb:104:in `service' d:/ruby/lib/ruby/1.8/webrick/httpserver.rb:65:in `run’  
d:/ruby/lib/ruby/1.8/webrick/server.rb:173:in `start_thread' d:/ruby/lib/ruby/1.8/webrick/server.rb:162:in `start’  
d:/ruby/lib/ruby/1.8/webrick/server.rb:162:in `start_thread' d:/ruby/lib/ruby/1.8/webrick/server.rb:95:in `start’  
d:/ruby/lib/ruby/1.8/webrick/server.rb:92:in `each' d:/ruby/lib/ruby/1.8/webrick/server.rb:92:in `start’  
d:/ruby/lib/ruby/1.8/webrick/server.rb:23:in `start' d:/ruby/lib/ruby/1.8/webrick/server.rb:82:in `start’  
d:/ruby/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/webrick\_server.rb:63:in  
`dispatch' d:/ruby/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/commands/servers/webrick.rb:59 d:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem\_original\_require’  
d:/ruby/lib/ruby/site\_ruby/1.8/rubygems/custom\_require.rb:27:in  
`require' d:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:495:in `require’  
d:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active\_support/dependencies.rb:342:in  
`new_constants_in' d:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:495:in `require’  
d:/ruby/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/commands/server.rb:39  
d:/ruby/lib/ruby/site\_ruby/1.8/rubygems/custom\_require.rb:27:in  
`gem_original_require' d:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require’  
script/server:3  
-e:4:in `load’  
-e:4

---

<div class="post-metadata">

**Author:** ![sunfish](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/96bed5/32.png) [@sunfish](https://www.ruby-forum.com/u/sunfish)\
**Post date:** [July 25, 2008, 4:06pm UTC](https://www.ruby-forum.com/t/auto-link-is-not-working/144107/4 "2008-07-25T16:06:04Z")

</div>

Hmm,  
Looks like you are using rails 1.2.3 and hitting on a known bug.

You have three options

1. Upgrade rails to the latest version.
2. Patch rails 1.2.3 installation

Edit  
d:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action\_view/helpers/text\_helper.rb

Replace line 372  
(?:/(?:(?:[~\w+%-]|(?:[,.;:][^\s$]))+)?)\* # path  
with  
(?:/(?:(?:[~\w+@%=()-]|(?:[,.;:][^\s$]))+)?)\* # path

and line 373  
(?:?[\w+%&=.;-]+)? # query string  
with  
(?:?[\w+@%&=.;-]+)? # query string

1. Add local fixes

Add the following right at the end of your environment.rb

require ‘action\_view/helpers/tag\_helper’  
require ‘html/document’  
module ActionView  
module Helpers  
module TextHelper  
def auto\_link\_urls(text, href\_options = {})  
extra\_options = tag\_options(href\_options.stringify\_keys) || “”  
text.gsub(AUTO\_LINK\_RE) do  
all, a, b, c, d = $&, $1, $2, $3, $4  
if a =~ /\<a\s/i # don’t replace URL’s that are already linked  
all  
else  
text = b + c  
text = yield(text) if block\_given?  
%(#{a}\<a href=“#{b==“www.”?“[http://www](http://www)  
.”:b}#{c}”#{extra\_options}\>#{text}#{d})  
end  
end  
end

```
  private
  AUTO_LINK_RE = %r{
    ( # leading text
    <\w+.*?>| # leading HTML tag, or
    [^=!:'"/]| # leading punctuation, or
    ^ # beginning of line
    )
    (
    (?:https?://)| # protocol spec, or
    (?:www\.) # www.*
    )
    (
    [-\w]+ # subdomain or domain
    (?:\.[-\w]+)* # remaining subdomains or domain
    (?::\d+)? # port
    (?:/(?:(?:[~\w\+@%=\(\)-]|(?:[,.;:][^\s$]))+)?)* # path
    (?:\?[\w\+@%&=.;-]+)? # query string
    (?:\#[\w\-]*)? # trailing anchor
    )
    ([[:punct:]]|<|$|) # trailing text
    }x unless const_defined?(:AUTO_LINK_RE)
  end
end

```

end

Let me know if that works.

Cheers,  
Ganesh G…  
SageWork([http://sagework.com](http://sagework.com)) Simplify IT

On Fri, Jul 25, 2008 at 6:54 PM, Sunny B. \<
