Ver Mensaje Individual
  #1 (permalink)  
Antiguo 12/05/2013, 02:07
cristh_men
 
Fecha de Ingreso: mayo-2013
Ubicación: ECUADOR--EL ORO
Mensajes: 1
Antigüedad: 11 años
Puntos: 0
Rails salvar ids en el detalle

Un cordial saludo amigos, esperando que me puedan ayudar, llevo 1 semana y no puedo dar con la solucion...
Lo que pasa que estoy haciendo mi tesis, un sistema de Matriculas y Notas en Ruby on Rails , con la BD en Mysql..
Mi problema es que NO puedo guardar los ids de estas tablas en el detalle.

Tengo estas 3 tablas :

ASIGNATURAS----MALLAS---NIVELS----->DETALLE: ASIGNATURAS_MALLAS_NIVELS

Como ven, las 3 apuntan a esa tabla de detalle, por lo tanto en el DETALLE se guardarán los Ids de: Asignatura_id ---Malla_id ---Nivel_id.

Las asignaturas ya las tengo creadas en el controlador de Asignaturas
Los niveles ya los tengo creados en el controlador de Niveles.

Y en el controlador de Malla, en la parte de la vista escojo el TIPO DE MALLA, y LISTO las asignaturas junto con los niveles que ya los tengo creados....Todo eso me sale, PERO CUANDO LOS ESCOJO Y LE DOY EN GUARDAR, NO SE ME GUARDAN EN MI TABLA DETALLE EN MYSQL.... SALE GUARDAR PERO NO APARECEN LOS IDS.

A continuacion, pondré mi codigo esperando que me ayudes amigo.


(No se si está bien el codigo en la parte del Create, no estoy seguro)
CONTROLADOR MALLA
def new
@asignatura = Asignatura.find(:all)
@clase = Clase.find(:all)
@nivel = Nivel.find(:all)
@malla = Malla.new
end
def create
[:malla][:asignatura_ids][:nivel_ids] ||= []
@malla = Malla.new (params[:malla][:asignatura_ids])
if @malla.save
redirect_to mallacurriculares_menu_principal_admin_path, :notice => 'MALLA CREADA CON EXITO'
end
end



Y VISTA DE MALLA
<%=form_for @malla , :url => {:action=>"create"} do |f| %>
<table> ESCOJA EL TIPO DE MALLA
<% for c in @clase %> #-----> @cLase contiene los tipos de Mallas que tengo.
<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.find(:all) %>
<tr>
<td> <%=radio_button_tag :nivel, n.id%><%= n.nivel_numero %><%= n.nivel_numero %></td>
</tr>
<%end%>
</table>
<br>
<table> ESCOJA LA ASIGNATURA
<%# for a in @asignatura %>
<% for a in Asignatura.find(:all) %>
<tr>
<td> <%=check_box_tag "malla[asignatura_ids][]", a.id, @malla.asignaturas.include?(a.id)%><%=a.asig_nombr e %></td>
<td></td>
</tr>
<%end%>
</table>
<br>
<%= f.submit "GUARDAR" %>
<%end%>




PONGO LOS MODELOS, POR SI ACASO ALGO ESTÉ MAL.
class Malla < ActiveRecord::Base
attr_accessible :mall_estado , :clase_id, :asignatura_ids
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 :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 :asignaturas_mallas_nivels
has_many :asignaturas, :through => :asignaturas_mallas_nivels
has_many :mallas, :through => :asignaturas_mallas_nivels
end

Y EL MODELO DETALLE
class AsignaturasMallasNivel < ActiveRecord::Base
attr_accessible :asignatura_id, :malla_id, :nivel_id
belongs_to :asignatura
belongs_to :malla
belongs_to :nivel
end

Me han salido distintos tipos de errores:

can't convert Symbol into Integer
STRINGFY.KEYS ["1","2"]arrays
etc, Pero no se que me estará fallando.