This project is archived and is in readonly mode.

#4077 ✓wontfix
Ingo

Wrong redirect after creation of nested singleton resource (using responder)

Reported by Ingo | March 1st, 2010 @ 03:16 PM | in 3.0.2

Hi,

I have a Rails 3.0.0.beta app with a singular :approval resource nested in a plural :posts resource. Now after creation of an approval, the responder attempts to redirect to '/posts/1/approval.1', not '/posts/1/approval'. Below are the relevant parts of the app

Cheers,
Ingo

config/routes.rb

resources :posts, :controller => 'posts' do
resource :approval, :controller => 'post_approval' end

app/controllers/post_approval_controller.rb

def create
@post = Post.find(params[:post_id]) @approval = @post.create_approval(params[:approval]) respond_with @post, @approval end

development.log

Started POST "/posts/1/approval" for 127.0.0.1 at 2010-03-01 16:09:30
Processing by PostApprovalController#create as HTML Parameters: {"commit"=>"Save Approval", "authenticity_token"=>"y1bI8bz+1fdAAI3vA3pCiKdoqJHvEijgGGGpkZMTL+Y=", "post_id"=>"1"} Post Load (0.3ms) SELECT "posts". FROM "posts" WHERE ("posts"."id" = 1) LIMIT 1 Approval Load (0.2ms) SELECT "approvals". FROM "approvals" WHERE ("approvals".post_id = 1) LIMIT 1 SQL (0.5ms) INSERT INTO "approvals" ("created_at", "post_id", "updated_at") VALUES ('2010-03-01 15:09:30.089291', 1, '2010-03-01 15:09:30.089291') Redirected to http://localhost:3000/posts/1/approval.1
Completed in 25ms with 302

Comments and changes to this ticket

  • José Valim

    José Valim March 3rd, 2010 @ 08:45 AM

    • Assigned user set to “José Valim”
    • Milestone cleared.

    The problem is not in responder, but in url generation. Try doing this:

    url_for [@post, @approval]
    

    What does it return you?

  • Ingo

    Ingo March 3rd, 2010 @ 12:22 PM

    yes, the above returns '/posts/1/approval.1'

  • José Valim

    José Valim March 3rd, 2010 @ 12:24 PM

    • Assigned user changed from “José Valim” to “josh”
    • State changed from “new” to “open”
  • josh

    josh March 6th, 2010 @ 07:17 PM

    • Assigned user cleared.
  • jonshea (at expandrive)

    jonshea (at expandrive) April 13th, 2010 @ 07:51 PM

    There’s a very similar test case in polymorphic_routes_test.rb. The method test_nesting_with_array_ending_in_singleton_resource tests the result of polymorphic_url([@project, :bid]), where Project is a plural resource and Bid is a singular resource. This test passes with the expected result, http://example.com/projects/16/bid.

    If the test is modified to use [@project, @bid] instead of [@project, :bid] then it fails as described above (http://example.com/projects/16/bid.17).

    I don’t know if perhaps it’s “wrong” for some reason to use an object for the singular resource instead of the symbol, but I’ve attached a patch for the modified test case regardless. If this is a real issue, then I’d be happy to look into the fix as well.

  • José Valim

    José Valim April 13th, 2010 @ 09:09 PM

    • State changed from “open” to “wontfix”

    @Jonshea, this is actually a known bug, since early Rails versions. We know how to reproduce it, but the solution is quite difficult, since polymorphic_url/url_for would have to ask the router how to mount it.

  • Jeremy Kemper

    Jeremy Kemper October 15th, 2010 @ 11:01 PM

    • Milestone set to 3.0.2
    • Importance changed from “” to “High”
  • Brendon

    Brendon March 11th, 2011 @ 08:17 AM

    +1 This happens even when the singular resource is earlier in the array.

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>

Attachments

Pages