Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Route not resolving properly

#919

While doing some integration testing on a mapped resource. I found that the route for the update action was not resolving.

If I called post with '/admin/books/239493' then the routing code would return params of {:action => '239493', :controller => 'admin/books'}

Somehow the id was being assigned to the action.

Reported by mudboy · August 27th, 2008 @ 08:52 PM

State: invalid
Milestone: 2.x
Assigned to: nobody
Importance: none

Activity

  1. mudboy
    mudboy

    It's very easy to repeat this bug, and it only seems to effect the integration test.

    step to reproduce.

    $ rails appname

    then

    $ script/generate scaffold Book title:string description:text

    run the migration

    $ rake db:migrate

    make a integration test

    $ script/generate integration_test Book

    Then add the following to the test.

    
      def test_truth
        id = books(:one).id
        post "/books/#{id}", :book => { :title => 'hello'}
        assert_response :success
    @@@@
    

    September 1st, 2008 @ 09:57 AM

  2. Mike Weber
    Mike Weber

    I don't believe this is a bug in Rails. The routing code is resolving to the only route that makes sense for a POST. But in a RESTful application, POSTs are only used for creating resources, which don't have an ID in the route. You'll need to use PUT in your test, rather than a POST.

    September 3rd, 2008 @ 05:30 AM

  3. mudboy
    mudboy

    Thanks for your insight Mike, I have been tearing my hair out trying to work out why this wasn't working. It just stems from my not understanding how the RESTful routes work.

    For future reference where is the best place to ask questions like this?

    September 3rd, 2008 @ 10:50 AM

  4. Michael Koziarski
    Michael Koziarski
    
    elsif ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS[:database_manager] == CGI::Session::CookieStore && session.respond_to?(:dbman) && session.dbman.respond_to?(:generate_digest)
    

    Couldn't you just do:

    
      if ActionController::Base.session_store == CGI::Session::CookieStore
    

    Or is there a case where we're using the cookie store and don't have dbman respond_to

    September 3rd, 2008 @ 12:56 PM

  5. Mike Weber
    Mike Weber

    The best resources for help with understanding Rails would either be the mailing list http://lists.rubyonrails.org/mai... or the #rubyonrails IRC channel on irc.freenode.net.

    September 3rd, 2008 @ 04:43 PM

  6. Tarmo Tänav
    Tarmo Tänav
    • State changed from new to invalid
    • Tag changed from 2.1, actionpack, bug, routing to 2.1, actionpack, bug, routing

    Looks like Michael actually intended to reply to #957 Generate form_authenticity_token correctly when using CookieStore and Secret ... :), closing this due to not being a bug.

    September 18th, 2008 @ 04:30 AM