link_to overriding problems

155 views
Skip to first unread message

Vinod Krishnan

unread,
Sep 30, 2006, 10:55:25 PM9/30/06
to rubyonra...@googlegroups.com
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: <div class="Logo">
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:in
`url_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:in
`url_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

Vishnu Gopal

unread,
Oct 1, 2006, 2:41:48 AM10/1/06
to rubyonra...@googlegroups.com
Overrides to link_to should go better in the ApplicationHelper. Try em there.

Vish

Bráulio Bhavamitra

unread,
Mar 27, 2014, 3:22:42 PM3/27/14
to rubyonra...@googlegroups.com, vis...@sent.com, g.vi...@gmail.com
Thanks Vish, I also had to make an alias_method_chain in the helper's self.included


On Sunday, October 1, 2006 3:41:48 AM UTC-3, Vishnu Gopal wrote:
Overrides to link_to should go better in the ApplicationHelper. Try em there.

Vish

Reply all
Reply to author
Forward
0 new messages