Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy is it in these two examples, one is redirecting to the correct URL while the other isn't?
    primarykey
    data
    text
    <p>I have a destroy method within a notecards controller that I am calling from a users page to delete a notecard. In the first example below.. the redirect is passing the notecard ID resulting in a page not found, while the second the user ID is being passed correctly finding the user page.. can someone help me understand why?</p> <h1>Redirects to user passing id of notecard</h1> <pre><code>def destroy @note = Notecard.find_by_id(params[:id]) delete_note(@note) redirect_to user_path(@current_user) end </code></pre> <h1>Redirects to user passing id of user</h1> <pre><code>def destroy @note = current_user.notecards.find_by_id(params[:id]) delete_note(@note) redirect_to user_path(@current_user) end </code></pre> <p>Update:</p> <p>Thanks for the responses. The code is here: <a href="https://github.com/incorvia/plumnotes/" rel="nofollow">https://github.com/incorvia/plumnotes/</a>.. The authentication is in the sessions helper and the sessions controller. As for the log:</p> <p>With Notecard.find_by_id(params[:id])</p> <pre><code>Started DELETE "/notecards/177" for 127.0.0.1 at 2011-10-15 11:53:38 -0400 Processing by NotecardsController#destroy as HTML Parameters: {"authenticity_token"=&gt;"WctbONb/qAO+hesHZ6Yw5zU19eCPNGeILIhxnW9Pi1Y=", "id"=&gt;"177"} Notecard Load (0.3ms) SELECT `notecards`.* FROM `notecards` WHERE `notecards`.`id` = 177 LIMIT 1 SQL (0.8ms) DELETE FROM `notecards` WHERE `notecards`.`id` = 177 Redirected to http://localhost:3000/users/177 Completed 302 Found in 12ms Started GET "/users/177" for 127.0.0.1 at 2011-10-15 11:53:39 -0400 Processing by UsersController#show as HTML Parameters: {"id"=&gt;"177"} User Load (0.3ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 9 LIMIT 1 User Load (0.6ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 177 LIMIT 1 Completed 404 Not Found in 14ms ActiveRecord::RecordNotFound (Couldn't find User with id=177): app/controllers/users_controller.rb:11:in `show' Rendered /Users/Kevin/.rvm/gems/ruby-1.9.2-p290@notes/gems/actionpack-3.1.0/lib/action_dispatch/middleware/templates/rescues/_trace.erb (1.4ms) Rendered /Users/Kevin/.rvm/gems/ruby-1.9.2-p290@notes/gems/actionpack-3.1.0/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (1.0ms) Rendered /Users/Kevin/.rvm/gems/ruby-1.9.2-p290@notes/gems/actionpack-3.1.0/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (4.6ms) </code></pre> <p>With current_user.notecards.find_by_id(params[:id])</p> <pre><code>Started DELETE "/notecards/179" for 127.0.0.1 at 2011-10-15 11:56:18 -0400 Processing by NotecardsController#destroy as HTML Parameters: {"authenticity_token"=&gt;"WctbONb/qAO+hesHZ6Yw5zU19eCPNGeILIhxnW9Pi1Y=", "id"=&gt;"179"} User Load (0.3ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 9 LIMIT 1 Notecard Load (0.6ms) SELECT `notecards`.* FROM `notecards` WHERE `notecards`.`user_id` = 9 AND `notecards`.`id` = 179 LIMIT 1 SQL (0.9ms) DELETE FROM `notecards` WHERE `notecards`.`id` = 179 Redirected to http://localhost:3000/users/9 Completed 302 Found in 95ms Started GET "/users/9" for 127.0.0.1 at 2011-10-15 11:56:18 -0400 Processing by UsersController#show as HTML Parameters: {"id"=&gt;"9"} </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload