Hi,
I’m new to ruby on rails and I’m working on a very small project. I’m in
the very early stages of development and I’m already stuck. Here’s the
problem:
I have two tables:
programs
- program_id primary key auto_increment
- program_name
modules
- module_id primary key auto_increment
- module_code
- module_name
- program_id foreign key
My first steps in coding are to do a simple admin section, where the
user can add new programs and modules. The ‘adding new programs’
functionality works, but the ‘adding new modules’ errors with the
following message: ‘wrong number of arguments (1 for 0)’. I’m guessing
this has something to do with the fact that program_id is a foreign in
the modules table. Can anybody advise on where I’m going wrong please?
Models:
class Program < ActiveRecord::Base
has_many :modules
end
class Module < ActiveRecord::Base
belongs_to :program
end
add_module View:
<% @page_title = “AddModule” -%>
<%= start_form_tag(:action => “save_module”) %>
Module Code:
<%= text_field(“module”, “module_code”, “size” => 40 ) %>
Module Name:
<%= text_field(“module”, “module_name”, “size” => 40 ) %>
Program Name:
<%= collection_select(“module”, “program_id” , Program.find_all,
“program_id”, “program_name”) %>
<%= submit_tag(" ADD ") %>
<%= end_form_tag %>
Controller:
def add_module
end
def save_module
@module = Module.new(params[:module])
if @module.save
flash[:notice] = "Module '" + @module.module_name + "' was
sucessfully added!"
redirect_to :action => ‘list’
else
redirect_to :action => “add_module”
end
end
Development Log:
Processing AdminController#save_module (for at 2007-05-08 16:35:06)
[POST]
Session ID: 61f30f5fc79afbce0720f9470ffc7766
Parameters: {“module”=>{“module_code”=>“Module X”, “program_id”=>“3”,
“module_name”=>“New Module”}, “commit”=>" ADD ",
“action”=>“save_module”, “controller”=>“admin”}
ArgumentError (wrong number of arguments (1 for 0)):