I have a profile, and this profile has many cursos (courses). I show all the courses a profile has on the show.html.erb of this profile.
<% for curso in @profile.cursos %>
<li><%=h curso.nome %> - <%=h curso.universidade %><br>
Ingresso em: <%=h curso.ano_ingresso %> - Encerra em: <%=h curso.ano_termino %>
<li>
<%= button_to 'Delete', { :action => "destroy", :id => curso.id },:confirm => "Are you sure?", :method => :delete %>
This way, I’m able to show all the courses a profile has on it’s page, but the button_to delete just doesn’t work. I have tried many things already, but I think I’m lost. Any idea on how I can create a link or a button or anything to delete the courses?
In your routes file
Then you can just use link_to method
Make sure you are providing the correct variables
profileandcourseThen in your courses_controller.rb you need to get the profile.
That will take you back to the correct profile url with it’s nested courses.
update
For new courses you can use the following link:
That will take you to the
newaction in the courses controller.You should read up on nested forms here.