This project is archived and is in readonly mode.
link_to in ActionView::TestCase uses ActionController::UrlRewriter's url_for instead of ActionView::Helpers::UrlHelper
-
Dan Pickett
close this ticket please, I had some old code in my test_helper.
Thanks, Dan
-
theflow
I'm having problems with this and haven't found a way to work around it in all cases.
In earlier versions of Rails (I'm coming from 2.1) link_to did this:
url = case options when String options when :back @controller.request.env["HTTP_REFERER"] || 'javascript:history.back()' else self.url_for(options) endwhereas now it just does a unconditional
url = url_for(options)So, if you include
ActionController::UrlWriter
somewhere and do a link_to with a named route you get the nice "TypeError: can't convert String into Hash" exception, because url_for in UrlWriter doesn't know how to handle Strings.
Would love to work on a patch, but I have no idea how this is supposed to work:
- just change the link_to implementation?
- change UrlWriter#url_for to handle Strings as options?
- I'm doing something wrong?
thanks,
Florian -
Michael Koziarski
- State changed from invalid to open
change UrlWriter#url_for to handle Strings as options?
This seems like the right place to handle this for me.
-
Michael Koziarski
At the same time it could be worthwhile attempting to rationalise the 3 different implementations of url_for to make sure that they code they share, isn't repeated.
I don't expect that you'll avoid having a few different implementations of url_for but the implementations should only differ in the ways that matter.
-
Courtenay
I'm seeing this too. Basically it means you can't use named/restful routes in your own classes (say, a presenter class).
-
Dan Pickett
- Tag set to bugmash
-
elcuervo
not reproducible , in master UrlWriter#url_for is currently supporting String as options.
actionpack/lib/action_dispatch/routing/url_for.rb:126
def url_for(options = nil) case options when String options when nil, Hash _router.url_for(url_options.merge((options || {}).symbolize_keys)) else polymorphic_url(options) end end -
Enrico Bianco
+1, not reproducible in master.
The
url_formethod inActionView::Helpers::UrlHelperalso handles strings (complete with new auto-escaping functionality):
(actionpack/lib/action_view/helpers/url_helper.rb:98)def url_for(options = {}) options ||= {} url = case options when String escape = true options when Hash options = { :only_path => options[:host].nil? }.update(options.symbolize_keys) escape = options.key?(:escape) ? options.delete(:escape) : false super when :back escape = false controller.request.env["HTTP_REFERER"] || 'javascript:history.back()' else escape = false polymorphic_path(options) end escape ? escape_once(url).html_safe : url end -
Rohit Arondekar
- Assigned user set to José Valim
Can somebody verify if this issue is still reproducible? Or else the ticket can be closed.
-
José Valim
- Assigned user cleared.
-
Rohit Arondekar
- State changed from open to resolved
I can't reproduce it in master either. Closing ticket assuming resolved.
-
patrick collins
in rails 2.3.5
If I do:
class Test include ActionView::Helpers include ActionController::UrlWriter default_url_options[:host] = "localhost:3000" def foo link_to "click me", "www.google.com" end end ... Test.new.fooI get:
can't convert String into Hash
Edited by Rohit Arondekar to fix formating.
-
Rohit Arondekar
- Milestone changed from 3.x to 2.x
- State changed from resolved to needs-more-info
Patrick, can you please try this on Rails 2.3.8 or even the 2-3-stable branch?
-
Neeraj Singh
- Milestone changed from 2.x to 2.3.9
- Importance changed from to Low
-
Christopher Dell
I can reproduce this bug on a clean 2.3.9 app adding Patrick's Test class to lib/test.rb and calling <%= Test.new.foo %> from a view.
Found this bug after trying to use link_to in a Presenter like court3nay alluded to.
-
rails
- State changed from needs-more-info to open
This issue has been automatically marked as stale because it has not been commented on for at least three months.
The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.
Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.
-
rails
- State changed from open to stale