Link_to overriding problems

Hi,
I am trying to override link_to in the ApplicationController as follows:

include ActionView::Helpers::UrlHelper
alias_method (:link_to_original, :link_to) unless
method_defined?(:link_to_original)

def link_to(name, options = {}, html_options = nil,
*parameters_for_method_reference)
puts “In my link_to”
link_to_original(name, options, html_options,
*parameters_for_method_reference)
end

I get the following error:

You have a nil object when you didn’t expect it!
The error occured while evaluating nil.url_for

Extracted source (around line #7):

4:


5: <%= link_to(image_tag(“logo4.gif”,
6: :alt => “logo”,
7: :border => 0),
8: {:controller => “main”,
9: :action => “index” })
10: %>

C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/actionpack1.12.1/lib/action_view/helpers/url_helper.rb:27:in
send' C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/actionpack1.12.1/lib/action_view/helpers/url_helper.rb:27:inurl_for’
C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/actionpack1.12.1/lib/action_view/helpers/url_helper.rb:27:in
send' C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/actionpack1.12.1/lib/action_view/helpers/url_helper.rb:27:inurl_for’
C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/actionpack1.12.1/lib/action_view/helpers/url_helper.rb:59:in
link_to' #{RAILS_ROOT}/app/views//layouts/_header.rhtml:7:in_run_rhtml_layouts__header’
#{RAILS_ROOT}/app/views/layouts/main_layout.rhtml:20:in
`_run_rhtml_layouts_main_layout’

Please help.

-Vinod

Overrides to link_to should go better in the ApplicationHelper. Try em
there.

Vish

Thanks Vish, I also had to make an alias_method_chain in the helper’s
self.included

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs