# Cancellare un record da una join table

**URL:** <https://www.ruby-forum.com/t/cancellare-un-record-da-una-join-table/195319>\
**Category:** IT\
**Created:** [September 21, 2010, 5:59pm UTC](https://www.ruby-forum.com/t/cancellare-un-record-da-una-join-table/195319 "2010-09-21T17:59:46Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![punkaruby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/49beb7/32.png) [@punkaruby](https://www.ruby-forum.com/u/punkaruby)\
**Post date:** [September 21, 2010, 5:59pm UTC](https://www.ruby-forum.com/t/cancellare-un-record-da-una-join-table/195319/1 "2010-09-21T17:59:46Z")

</div>

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…

☹

non succede niente…

Apprezzati suggerimenti…

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

:Â°-(

Grazie a todos

---

<div class="post-metadata">

**Author:** ![punkaruby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/49beb7/32.png) [@punkaruby](https://www.ruby-forum.com/u/punkaruby)\
**Post date:** [September 22, 2010, 12:13pm UTC](https://www.ruby-forum.com/t/cancellare-un-record-da-una-join-table/195319/2 "2010-09-22T12:13:31Z")

</div>

Ti incollo le api 🙂

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)
> 
> ```
