auto_link is not working

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?

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 :stuck_out_tongue:

auto_link and truncate can handle nil arguments.

Cheers,

Ganesh Gunasegaran

SageWork(http://sagework.com) Simplify IT

Ganesh Gunasegaran 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 :stuck_out_tongue: auto_link and truncate can handle nil arguments. Cheers, Ganesh Gunasegaran SageWork(http://sagework.com) Simplify IT

On Fri, Jul 25, 2008 at 5:22 PM, Sunny Bogawat <

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

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.”: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 Gunasegaran.

SageWork(http://sagework.com) Simplify IT