ga-wdi-exercises / project2

[project]
1 stars 30 forks source link

placing edit path for further nested element on current show page #863

Closed twelve13 closed 7 years ago

twelve13 commented 7 years ago

Hi, I have a show posts view that shows (nested) notes, and I'd like to have the option of editing the notes there, and not on an individual show page for each note.

I'm having trouble figuring out how to reconcile the fact that :id refers to the post's id for the posts#show, and then refers to the note's id for the notes#edit:

board_post_path GET /boards/:board_id/posts/:id(.:format) posts#show

edit_board_post_note_path GET /boards/:board_id/posts/:post_id/notes/:id/edit(.:format)notes#edit

if I have this in my notes controller

def edit @board = Board.find(params[:board_id]) @post = @board.posts.find(params[:post_id]) @note = @post.notes.find(params[:id]) end

I get

No route matches {:action=>"edit", :board_id=>"17", :controller=>"notes", :id=>nil, :post_id=>"52"} missing required keys: [:id]

It can't find the id for the note....

juancgarcia commented 7 years ago

@twelve13 You should be able to insert edit forms for each of your notes on the posts#show view. If you're not sure where to put them, commit and push your work to a WIP branch then share a link so I can point you in the right direction.

If you want the edit forms to be normally hidden, then that would be an opportunity to use some JS on your view as a Silver/Gold feature to toggle visibility of the form(s)

twelve13 commented 7 years ago

I tried putting the form directly on the posts#show view, but am still running into the issue of figurint out how to grab the :id of the note..

https://github.com/twelve13/studii/tree/crud

thanks!

juancgarcia commented 7 years ago

Ah, so you're placing the form_for [@board, @post, @note] in a place where there is no @note variable defined. You do, however, have note inside the block for @post.notes.each do |note| on /app/views/posts/show.html.erb line 13

twelve13 commented 7 years ago

yyeesssssss