I’m having a slight issue with a controller action. The behavior i’m after is the option to edit a note. I want the user to be able to edit the note, just like they created the note, in a modal(twitter bootstrap). Creating a note this way works fine. The problem is coming to edit the note. The main issue is that I need to always know the exact note id when a user clicks on a “edit” button. To complicate things a bit more, there is a “dashboard” controller/model which acts as a container for “notes” and other things.
Here is the code/link I have in the view on the dashboard which displays all the users current notes.
= link_to "Edit Note", "update_note/#{n.id}",{:note_id => "#{n.id}"}
So Here I am sending some params contain the note id. Then in the controller action, in the dashboard (the container)
def update_note
@user = current_user
@edit_note_id = params[:params1]
redirect_to dashboard_path and return
respond_to do |format|
format.html { render "#modal_edit_notes"}
end
end
So at point I have the unique note id, and instantiating something so when hopefully the modal loads up I can create a form based on that. The issue that I’m having is getting the controller at this point to go back to the dashboard, and pop up the modal, now that I have the note.id.
To trigger the modal, I normally would do a
href = #modal_edit_notes, data-toggle = "modal"
Thanks!
OK, you have two options here.
Embed a form inside a hidden element for every single note you display, and then just have that pre-rendered form show up in the modal when you want to edit that particular note.
Load the content of the modal via ajax, this will require a little bit of custom JS to make it work with the bootstrap modals, but isn’t too difficult. This is how I would do it.
Also, as a side point, the
update_notemethod really should be aupdatemethod in aNotesController.