This project is archived and is in readonly mode.
URL Generation for routes that point to a Rack application include the controller and action parameters
Reported by Brad Gessler | April 4th, 2010 @ 10:39 PM | in 3.0.2
Given a route file:
SocketChat::Application.routes.draw do |map|
resources :channels do
resources :people
resources :events do
collection do
get :socket, :to => SocketController
end
end
end
end
and the URL generation code
socket_channel_events_url(@channel, :scheme => 'ws')
The following is generated:
ws://localhost:3000/channels/4bb8d4c7b0499803fe000002/events/socket?action=show&controller=channels
When I expected:
ws://localhost:3000/channels/4bb8d4c7b0499803fe000002/events/socket
Comments and changes to this ticket
-
Rizwan Reza April 5th, 2010 @ 02:08 AM
- State changed from new to open
- Tag changed from rails3 routes to rails3, routes
- Milestone cleared.
Can you provide a failing test case?
-
Rizwan Reza April 5th, 2010 @ 02:31 AM
I cannot reproduce this. It is correctly generating URLs for a rack app at my side. You can write a failing test case in
routing_test.rb
. -
Gaël Deest April 6th, 2010 @ 06:38 PM
Hi, this might be related. Here is my controller:
class MyControllerController < ApplicationController before_filter { |controller| render :text => controller.url_for(controller.params) } def my_action; end end
Output:
http://localhost:3000/my_controller/my_action?action=my_action&controller=my_controller
-
Dan Pickett May 9th, 2010 @ 06:26 PM
- Tag changed from rails3, routes to bugmash, rails3, routes
-
Dan Pickett May 9th, 2010 @ 06:27 PM
- no changes were found...
-
Bobby Wilson May 29th, 2010 @ 12:50 AM
I also could not reproduce this.
Brad,
Can you simplify your problem code any? -
Indrek Juhkam June 1st, 2010 @ 03:31 PM
The problem is
:to => SocketController
part. Rails doesn't translate it. If you change it to:to => "socket#index"
then it works.How to reproduce:
Create Test1Controller and Test2Controller.
To routes.rb add
match "test1", :to => "test1#index" match "test2", :to => Test2Controller, :as => :test2
Now add an index action to the Test1Controller
def index render :text => test2_url end
Go to /test1 url and see the response.
-
Rohit Arondekar June 4th, 2010 @ 03:38 PM
Confirmed on Rails master (on Ruby 1.9.2-head) by following instructions given by Indrek. Also note that test2_path has the same problem. Also the rake routes output:
test1 /test1 {:controller=>"test1", :action=>"index"}
test2 /test2And just glancing through http://edgeapi.rubyonrails.org/classes/ActionDispatch/Routing.html I don't Rails is expected to handle Test2Controller in :to.
-
Neeraj Singh June 25th, 2010 @ 09:12 PM
- Assigned user set to José Valim
Can someone verify if the patch is working?
-
José Valim June 25th, 2010 @ 11:18 PM
- State changed from open to wontfix
-1 for supporting the controller class in the router API (and you don't want that, because it will force ActionController to load if you are using simple stuff like rake tasks).
-
Andrew White June 25th, 2010 @ 11:35 PM
- State changed from wontfix to invalid
Actually it's invalid - you just need to specify the end point.
resources :channels do resources :people resources :events do collection do get :socket, :to => UsersController.action(:show) end end end
The original subject of the ticket is invalid as well:
andyw$ rails c >> app.socket_channel_events_url('1', :protocol => 'ws') => "ws://www.example.com/channels/1/events/socket"
-
Andrew White June 27th, 2010 @ 08:12 AM
- State changed from invalid to open
- Milestone cleared.
- Importance changed from to High
Sorry, this isn't invalid. The problem occurs when you have recall params which get added to the url as there isn't a controller and action when routing to a block, proc or class. Attached patch removes controller and action when the target route isn't a Dispatcher instance.
-
Repository June 27th, 2010 @ 08:23 AM
- State changed from open to resolved
(from [91b52c795f62aa15505f2f098bc86d6f6db75105]) Normalize recall params when the route is not a standard route otherwise :controller and :action may appear in the generated url [#4326 state:resolved]
Signed-off-by: José Valim jose.valim@gmail.com
http://github.com/rails/rails/commit/91b52c795f62aa15505f2f098bc86d...
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>
People watching this ticket
Attachments
Referenced by
- 4718 Some url helpers are broken Duplicate of #4326
- 4326 URL Generation for routes that point to a Rack application include the controller and action parameters (from [91b52c795f62aa15505f2f098bc86d6f6db75105]) Normali...