This project is archived and is in readonly mode.
url_for failing with singular resource
-
Ryan Bigg
I would suggest this is a bug as it is definitely surprising behaviour. I would expect this to return a similar result to
polymorphic_path.Please submit a test + patch if you could.
-
José Valim
- Assigned user changed from José Valim to josh
- Milestone cleared.
-
Daniel Lopes
Why this bug was assigned to milestone 3.0? It shouldn't be released with Rails 2.3.6?
The problem is with url_for method, when we send a active record object that maps to a singleton resource the url_for try use the instance as format (that's why we have /account.%23%3Caccount:0x103629d60%3E wich is escaped version of /account.<account:object_id>).
-
Daniel Lopes
To be more specific the options passed to url_for is:
{:action=>"show", :controller=>"accounts", :format=>#, :use_route=>:account, :only_path=>false}
-
José Valim
You haven't told which Rails version the bug occurs. Anyway, since we are working in the 3.0 branch, we have higher priority in fixing it on 3.0. You/we could backport the fix later.
-
Daniel Lopes
Thanks Valim.
About the bug, it happens because url_for call the named route when you send a record to it. In some context I don't think it's wrong, like this:
account_url #=> "http://www.example.com/account"and when you send a record (wich don't make sense in this context):
account_url Account.first #=> "http://www.example.com/account.%23%3Caccount:0x102bb9fb0%3E"But the problem is when you will try to use things like form_for in records that map to singleton resources:
<% form_for @account do |f| %>
... <% end %>I'm still not sure it's a bug. What do you think?
-
José Valim
I would regard this is a bug, although this is a known bug. I guess there is not a simple fix for it on Rails 2.3, so the question really is if Rails 3.0 router can help us on this and if so, how hard would be to backport the fix for Rails 2.3.
Josh will be able to tell us.
-
josh
- State changed from new to invalid
This is a known limitation.
I don't think there is an easy to implement this either. Then we'd have to deal with the case where you have resources and resource :account.