I don''t know how to solve something about a project I''m doing
in Ruby on
Rails.
I want to save the IDS of my 3 models to my table DETAILS between these,
my BD is Mysql.
ASIGNATURAS--MALLAS--NIVELS-------->ASIGNATURA_ID--_MALLAS_ID--_NIVELS_ID
In the view MALLA, i list my asignaturas, mallas and niveles, and in the
controller MALLA i want to save the arrays to my model
asignaturas_mallas_nivels.
class Malla < ActiveRecord::Base
attr_accessible :mall_estado , :clase_id, :nivel_ids, :asignatura_ids,
:nivel_id
belongs_to :clase
has_many :asignaturas_mallas_nivels
has_many :asignaturas, :through => :asignaturas_mallas_nivels
has_many :nivels, :through => :asignaturas_mallas_nivels
end
class Asignatura < ActiveRecord::Base
attr_accessible :asig_abreviat, :asig_nombre
has_many :distributivos
has_many :notas
has_many :asignaturas_mallas_nivels
has_many :mallas, :through => :asignaturas_mallas_nivels
has_many :nivels, :through => :asignaturas_mallas_nivels
end
class Nivel < ActiveRecord::Base
attr_accessible :nivel_descrip, :nivel_numero, :nivele_id
has_many :cursos
belongs_to :nivele
has_many :asignaturas_mallas_nivels
has_many :mallas, :through => :asignaturas_mallas_nivels
has_many :asignaturas, :through => :asignaturas_mallas_nivels
end
class AsignaturasMallasNivel < ActiveRecord::Base
attr_accessible :asignatura_id, :malla_id, :nivel_id
belongs_to :asignatura
belongs_to :malla
belongs_to :nivel
end
My controller is:
def new
@asignatura = Asignatura.find(:all)
@clase = Clase.find(:all)
@nivel = Nivel.find(:all)
@malla = Malla.new
end
def create
params[:malla][:nivel_ids][:asignatura_ids]
@malla = Malla.new(params[:asignatura_ids],[:nivel_ids], [:malla])
if @malla.save
redirect_to mallacurriculares_menu_principal_admin_path, :notice
=> ''MALLA CREADA CON EXITO''
end
end
******************************************************************
AND IN MY VIEW I HAVE:
<%=form_for @malla , :url => {:action=>"create"} do |f| %>
<table> ESCOJA EL TIPO DE MALLA
<% for c in @clase %>
<tr>
<td> <%= f.radio_button :clase_id, c.id%> <%= c.tip_mall_descrip
%></td>
</tr>
<% end %>
</table>
<br>
<table> ESCOJA EL CURSO O NIVEL
<% for n in @nivel %>
<tr>
<td> <%= check_box_tag "malla[nivel_ids][]", n.id,
@malla.nivels.include?(n)%> <%= n.nivel_numero %></td>
</tr>
<%end%>
</table>
<br>
<br>
<table> ESCOJA LA ASIGNATURA
<% for a in @asignatura %>
<tr>
<td> <%= check_box_tag "malla[asignatura_ids][]", a.id,
@malla.asignaturas.include?(a)%></td>
<td><%= a.asig_nombre %></td>
</tr>
<%end%>
</table>
<br>
<%= f.submit "GUARDAR" %>
<%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:
**cant convert symbol into integer or
**undefined method `stringify_keys''
Please, someone help me, i''m doing my thesis.
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.