Forum: Ruby on Rails to customize link_to

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Dc906dfeaa19b1d9872255515eea4aba?d=identicon&s=25 paulchin (Guest)
on 2005-11-26 02:04
(Received via mailing list)
Hi I'm trying to customize the link_to helper and keep getting this
error,
any suggestion how can I work arround it?

this is the error message:

undefined method `link_to' for module `UserHelper'


this is my users_helper.rb:

module UsersHelper

  alias_method :link_to_original, :link_to
  alias_method :link_to, :link_to_permission


def link_to_permission(name, options = {}, html_options = nil,
*parameters_for_method_reference)
  if @permission
    if html_options
          html_options = html_options.stringify_keys
          convert_options_to_javascript!(html_options)
          tag_options = tag_options(html_options)
        else
          tag_options = nil
        end
        url = html_escape(options.is_a?(String) ? options :
url_for(options,
*parameters_for_method_reference))
        "<a href_1234=\"#{url}\"#{tag_options}>#{name||url}</a>"
else
	link_to_original( name, options,
html_options,*parameters_for_method_reference )
end

end

end
C618e1d9ffa1bd1a6b6edc8ad4edec63?d=identicon&s=25 mannl (Guest)
on 2005-11-26 03:16
(Received via mailing list)
>   alias_method :link_to_original, :link_to

Isn't it:

alias link_to_original link_to

or the other way around:

alias link_to link_to_original

but no commas, and no :interns
Dc906dfeaa19b1d9872255515eea4aba?d=identicon&s=25 paulchin (Guest)
on 2005-11-28 04:26
(Received via mailing list)
hi, followed your suggestion, still having the same problem:


 NameError in <controller not set>#<action not set>

undefined method `link_to' for module `UsersHelper'

RAILS_ROOT: ./script/../config/..
Application Trace | Framework Trace | Full Trace

#{RAILS_ROOT}/app/helpers/users_helper.rb:5
#{RAILS_ROOT}/app/controllers/users_controller.rb:2
routing.rb:234:in `traverse_to_controller'
generated/routing/recognition.rb:3:in `eval'
generated/routing/recognition.rb:3:in `recognize_path'

d:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.2.3/lib/active_support/depend
encies.rb:207:in `load'
d:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.2.3/lib/active_support/depend
encies.rb:207:in `load'
d:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.2.3/lib/active_support/depend
encies.rb:39:in `require_or_load'
d:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.2.3/lib/active_support/depend
encies.rb:22:in `depend_on'
d:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.2.3/lib/active_support/depend
encies.rb:178:in `require_dependency'
d:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.2.3/lib/active_support/depend
encies.rb:178:in `require_dependency'
d:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.11.0/lib/action_controller/helpe
rs.rb:70:in `helper'
d:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.11.0/lib/action_controller/helpe
rs.rb:61:in `each'
d:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.11.0/lib/action_controller/helpe
rs.rb:61:in `helper'
d:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.11.0/lib/action_controller/helpe
rs.rb:116:in `inherited_without_api'
d:/ruby/lib/ruby/gems/1.8/gems/actionwebservice-0.9.3/lib/action_web_service
/container/action_controller_container.rb:86:in
`inherited_without_action_controller'
d:/ruby/lib/ruby/gems/1.8/gems/actionwebservice-0.9.3/lib/action_web_service
/dispatcher/action_controller_dispatcher.rb:34:in `inherited'
d:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.2.3/lib/active_support/depend
encies.rb:207:in `load'
d:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.2.3/lib/active_support/depend
encies.rb:207:in `load'
d:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.2.3/lib/active_support/depend
encies.rb:39:in `require_or_load'
d:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.2.3/lib/active_support/depend
encies.rb:22:in `depend_on'
d:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.2.3/lib/active_support/depend
encies.rb:178:in `require_dependency'
d:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.2.3/lib/active_support/depend
encies.rb:178:in `require_dependency'
d:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.2.3/lib/active_support/depend
encies.rb:134:in `load_file!'
d:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.2.3/lib/active_support/depend
encies.rb:97:in `const_load!'
d:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.2.3/lib/active_support/depend
encies.rb:80:in `each'
d:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.2.3/lib/active_support/depend
encies.rb:80:in `const_load!'
d:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.2.3/lib/active_support/depend
encies.rb:72:in `const_missing'
d:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.11.0/lib/action_controller/routi
ng.rb:234:in `traverse_to_controller'
d:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.11.0/lib/action_controller/routi
ng.rb:458:in `recognize!'
d:/ruby/lib/ruby/gems/1.8/gems/rails-0.14.3/lib/dispatcher.rb:38:in
`dispatch'
d:/ruby/lib/ruby/gems/1.8/gems/rails-0.14.3/lib/webrick_server.rb:117:in
`handle_dispatch'
d:/ruby/lib/ruby/gems/1.8/gems/rails-0.14.3/lib/webrick_server.rb:83: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:155:in `start_thread'
d:/ruby/lib/ruby/1.8/webrick/server.rb:144:in `start'
d:/ruby/lib/ruby/1.8/webrick/server.rb:144:in `start_thread'
d:/ruby/lib/ruby/1.8/webrick/server.rb:94:in `start'
d:/ruby/lib/ruby/1.8/webrick/server.rb:89:in `each'
d:/ruby/lib/ruby/1.8/webrick/server.rb:89:in `start'
d:/ruby/lib/ruby/1.8/webrick/server.rb:79:in `start'
d:/ruby/lib/ruby/1.8/webrick/server.rb:79:in `start'
d:/ruby/lib/ruby/gems/1.8/gems/rails-0.14.3/lib/webrick_server.rb:69:in
`dispatch'
d:/ruby/lib/ruby/gems/1.8/gems/rails-0.14.3/lib/commands/servers/webrick.rb:
59
d:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:18:in
`require__'
d:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:18:in
`require'
d:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.2.3/lib/active_support/depend
encies.rb:214:in `require'
d:/ruby/lib/ruby/gems/1.8/gems/rails-0.14.3/lib/commands/server.rb:28
d:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:18:in
`require__'
d:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:18:in
`require'
d:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.2.3/lib/active_support/depend
encies.rb:214:in `require'
script/server:3

#{RAILS_ROOT}/app/helpers/users_helper.rb:5
d:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.2.3/lib/active_support/depend
encies.rb:207:in `load'
d:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.2.3/lib/active_support/depend
encies.rb:207:in `load'
d:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.2.3/lib/active_support/depend
encies.rb:39:in `require_or_load'
d:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.2.3/lib/active_support/depend
encies.rb:22:in `depend_on'
d:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.2.3/lib/active_support/depend
encies.rb:178:in `require_dependency'
d:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.2.3/lib/active_support/depend
encies.rb:178:in `require_dependency'
d:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.11.0/lib/action_controller/helpe
rs.rb:70:in `helper'
d:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.11.0/lib/action_controller/helpe
rs.rb:61:in `each'
d:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.11.0/lib/action_controller/helpe
rs.rb:61:in `helper'
d:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.11.0/lib/action_controller/helpe
rs.rb:116:in `inherited_without_api'
d:/ruby/lib/ruby/gems/1.8/gems/actionwebservice-0.9.3/lib/action_web_service
/container/action_controller_container.rb:86:in
`inherited_without_action_controller'
d:/ruby/lib/ruby/gems/1.8/gems/actionwebservice-0.9.3/lib/action_web_service
/dispatcher/action_controller_dispatcher.rb:34:in `inherited'
#{RAILS_ROOT}/app/controllers/users_controller.rb:2
d:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.2.3/lib/active_support/depend
encies.rb:207:in `load'
d:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.2.3/lib/active_support/depend
encies.rb:207:in `load'
d:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.2.3/lib/active_support/depend
encies.rb:39:in `require_or_load'
d:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.2.3/lib/active_support/depend
encies.rb:22:in `depend_on'
d:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.2.3/lib/active_support/depend
encies.rb:178:in `require_dependency'
d:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.2.3/lib/active_support/depend
encies.rb:178:in `require_dependency'
d:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.2.3/lib/active_support/depend
encies.rb:134:in `load_file!'
d:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.2.3/lib/active_support/depend
encies.rb:97:in `const_load!'
d:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.2.3/lib/active_support/depend
encies.rb:80:in `each'
d:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.2.3/lib/active_support/depend
encies.rb:80:in `const_load!'
d:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.2.3/lib/active_support/depend
encies.rb:72:in `const_missing'
routing.rb:234:in `traverse_to_controller'
generated/routing/recognition.rb:3:in `eval'
d:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.11.0/lib/action_controller/routi
ng.rb:234:in `traverse_to_controller'
generated/routing/recognition.rb:3:in `recognize_path'
d:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.11.0/lib/action_controller/routi
ng.rb:458:in `recognize!'
d:/ruby/lib/ruby/gems/1.8/gems/rails-0.14.3/lib/dispatcher.rb:38:in
`dispatch'
d:/ruby/lib/ruby/gems/1.8/gems/rails-0.14.3/lib/webrick_server.rb:117:in
`handle_dispatch'
d:/ruby/lib/ruby/gems/1.8/gems/rails-0.14.3/lib/webrick_server.rb:83: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:155:in `start_thread'
d:/ruby/lib/ruby/1.8/webrick/server.rb:144:in `start'
d:/ruby/lib/ruby/1.8/webrick/server.rb:144:in `start_thread'
d:/ruby/lib/ruby/1.8/webrick/server.rb:94:in `start'
d:/ruby/lib/ruby/1.8/webrick/server.rb:89:in `each'
d:/ruby/lib/ruby/1.8/webrick/server.rb:89:in `start'
d:/ruby/lib/ruby/1.8/webrick/server.rb:79:in `start'
d:/ruby/lib/ruby/1.8/webrick/server.rb:79:in `start'
d:/ruby/lib/ruby/gems/1.8/gems/rails-0.14.3/lib/webrick_server.rb:69:in
`dispatch'
d:/ruby/lib/ruby/gems/1.8/gems/rails-0.14.3/lib/commands/servers/webrick.rb:
59
d:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:18:in
`require__'
d:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:18:in
`require'
d:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.2.3/lib/active_support/depend
encies.rb:214:in `require'
d:/ruby/lib/ruby/gems/1.8/gems/rails-0.14.3/lib/commands/server.rb:28
d:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:18:in
`require__'
d:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:18:in
`require'
d:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.2.3/lib/active_support/depend
encies.rb:214:in `require'
script/server:3

This error occured while loading the following files:
   ./script/../config/../app/controllers/users_controller.rb
   users_helper.rb
This topic is locked and can not be replied to.