Ruby on rails get ids to my database

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.

On 14 May 2013 06:19, cristhian Campoverde [email protected] wrote:

I want to save the IDS of my 3 models to my table DETAILS between these,
my BD is Mysql.

Why have you posted this again? I have replied to your first posting.

Colin

Hi Colin, really ?? sorry, I tried to simplificate my question…!

Please, if you know how to solve, tell me men.

The trouble Colin is I accidentally deleted my first post, it was the
first time i signed up, so i was trying to know how the forum works.

Please man help me with that, really I need to solve it for my thesis.

On 14 May 2013 08:03, cristhian Campoverde [email protected] wrote:

Hi Colin, really ?? sorry, I tried to simplificate my question…!

Please, if you know how to solve, tell me men.

See my reply to your initial posting.

Colin

On 14 May 2013 09:13, cristhian Campoverde [email protected] wrote:

The trouble Colin is I accidentally deleted my first post, it was the
first time i signed up, so i was trying to know how the forum works.

Please man help me with that, really I need to solve it for my thesis.

Please quote the previous message when replying as this is actually a
mailing list not a forum, though you may be accessing it using a
forum-like interface. My reply was:

You need to show us the exact error and the line of code it is failing
on (with the lines around it). First, though, have a look at the
Rails Guide on Debugging which will show you techniques that you can
use to debug your code.

Colin

Thanks for you replying Colin:

Look, this’s my message of error:

NoMethodError in MallacurricularesController#create
undefined method `save’ for []:ActiveRecord::Relation

Line rb:32:in `create-----> the line when i try to save.

Parameters:
{“utf8”=>“✓”,
“authenticity_token”=>“CEX4yZeFmrSOspseMm2/d8rzPzu/3FYI2w8d7XZ1Ji0=”,
“malla”=>{“clase_id”=>“1”,
“subjects_ids”=>[“3”,
“4”,
“5”]},
“level”=>“3”,
“commit”=>“GUARDAR”}

The parameters looks good, and my controller is:

def new
@asignatura = Asignatura.find(:all)
@clase = Clase.find(:all)
@nivel = Nivel.find(:all)
@malla = Malla.new
end

def create
@malla = Malla.new(params[:malla])
@subject = @malla.subjects(params[:subject_ids])
@level = @malla.levels(params[:level])

   if @malla.save and @subject.save and @level.save

   redirect_to mallacurriculares_menu_principal_admin_path,  :notice

=> ‘MALLA created’
end
end

In my controller i want to save the “ids” that i chose in the view form
to my model: subject_malla_level.

And i dont know how to do it, please help men :frowning: