I want to save the IDS of my 3 models to my table DETAILS between these,
my BD is Mysql.
SUBJECTS–MALLAS–LEVELS-------->SUBJECT_ID–_MALLA_ID–_LEVEL_ID
In the view MALLA, i list my subjects, mallas and levels, and in the
controller MALLA i try to get save the arrays to
subjects_mallas_levels.
class Malla < ActiveRecord::Base
attr_accessible :mall_estado , :class_id, :level_ids, :subject_ids,
:nivel_id
belongs_to :class
has_many :subjects_mallas_levels
has_many :subjects, :through => :subjects_mallas_levels
has_many :nivels, :through => :subjects_mallas_levels
end
class Subject < ActiveRecord::Base
attr_accessible :subject_abreviat, :subject_name
has_many :subjects_mallas_levels
has_many :mallas, :through => :subjects_mallas_levels
has_many :levels, :through => :subjects_mallas_levels
end
class Levels < ActiveRecord::Base
attr_accessible :level_descrip, :level_numero, :nivele_id
has_many :courses
belongs_to :nivele
has_many :subjects_mallas_levels
has_many :mallas, :through => :subjects_mallas_levels
has_many :subjects, :through => :subjects_mallas_levels
end
class SubjectsMallasLevels < ActiveRecord::Base
attr_accessible :subject_id, :malla_id, :level_id
belongs_to :asignatura
belongs_to :malla
belongs_to :nivel
end
My controller is:
def new
@subject = Subject.find(:all)
@clase = Clase.find(:all)
@level = Level.find(:all)
@malla = Malla.new
end
I think, my method create is wrong.
def create
params[:malla][:level][:subject_ids]
@malla = Malla.new(params[:subject_ids][:level][:malla])
if @malla.save
redirect_to mallacurriculares_menu_principal_admin_path, :notice
=> ‘MALLA CREATED’
end
end
AND IN MY VIEW MALLA I HAVE:
<%=form_for @malla , :url => {:action=>“create”} do |f| %>
<% for c in @class %>
<%=f.radio_button :clase_id, c.id%> <%=c.tip_mall_descrip%>
<% end %>
<% for n in Level.find(:all) %>
<%=radio_button_tag :level, n.id%><%= n.level_number %>
<%end%>
<% for a in @subject%>
<%=check_box_tag
“malla[subject_ids][]”,a.id,@malla.subject.include?(a)%>
<%= a.subject_name%>
<%end%>
<%=f.submit “SAVE”%>
<%end%>
My problem is, when I chose the options in my checkbox and radiobutton,
I can’t get their “ids” in my table ASIGNATURAS_MALLAS_NIVELS, sometimes
I get this errors:
Please, someone help me, i’m doing my thesis.