I have a problem with simple delete action.
I have a view
%p
Name:
= @element.name
%p
Description:
= @element.description
%p
= link_to 'edit', edit_element_path(@element)
|
= link_to 'delete', @element, :confirm => 'Are you shure?', :method => :delete
When I try to click on that delete in browser and clik OK it says that it can not delete from unexisting table elements_muscle_groups, why does he tries to delete from that unexisting table anyway?
By the way I am using Rails 4
You can see the controller code on screenshot.
Sorry for eng and ty for help.
EDIT: Hi I have one more thing to add,
Element
has_and_belongs_to_many :muscle_groups
MuscleGroup
has_and_belongs_to_many :elements
so maybe it should delete from elements_muscle_groups, but why does that table does not exist then?
from rails api:
http://apidock.com/rails/ActiveRecord/Associations/ClassMethods/has_and_belongs_to_many
has_and_belnogs_to_many: Specifies a many-to-many relationship with another class. This associates two classes via an intermediate join table. Unless the join table is explicitly specified as an option, it is guessed using the lexical order of the class names. So a join between Developer and Project will give the default join table name of “developers_projects” because “D” outranks “P”.
so you need to make sure you have a table called
elements_muscle_groups
with element_id: integer
and muscle_group_id:integer