Cancellare un record da una join table

Ciao,
devo cancellare un record da una join table (courses_teachers) vale a
dire che devo cancellare l’abbinamento di un docente in un corso (non
devo cancellare il docente).

ho creato il seguente metodo nel controller courses:

def deleteTeach
@course = Course.find(session[:id_corso])
@teacher = Teacher.find(params[:id])
@course.teachers.delete(@teacher)
end

nella view (lo show del corso) ho messo le seguenti istruzioni:

<%= link_to image_tag(“delete.gif”, :border=>0), :confirm => ‘Sicuri ?’,
:method => :deleteTeach %>

Ma quando clicco… Rails mi ride in faccia…

:frowning:

non succede niente…

Apprezzati suggerimenti…

(“cambia mestiere” non è un suggerimento che nel contingente mi aiuta a
risolvere il problema…)

:°-(

Grazie a todos

Ti incollo le api :slight_smile:

Delete an object (or multiple objects) where the id given matches the
primary_key. A SQL DELETE command is executed on the database which
means that no callbacks are fired off running this. This is an efficient
method of deleting records that don‘t need cleaning up after or other
actions to be taken.
Objects are not instantiated with this method.
Attributes

id - Can be either an Integer or an Array of Integers.
Examples

Delete a single object

Todo.delete(1)

Delete multiple objects

todos = [1,2,3]
Todo.delete(todos)

se vuoi cancellare Teacher dovresti fare:
Teacher.delete(params[:id])

An Car wrote:

@course  = Course.find(session[:id_corso])
@teacher = Teacher.find(params[:id])
@course.teachers.delete(@teacher)

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs