All,
This is really starting to get me as i can’t figure out why I am
getting this error. Here is what is going on. I have a table called
items and a item controller. When I add a new item to the items table
I am also creating several associated tables. the code for this so
that you can follow along is:
def create
@item = Item.new(params[:item])
# The item belongs to the user
@user.reload
@item.user = @user
if @item.save
itemtablename = "Item_#{@item.id}"
ActiveRecord::Schema.define do
create_table(itemtablename, :options => 'ENGINE=InnoDB
DEFAULT CHARSET=utf8’) do |t|
t.column :field_type, :string, :null => false
t.column :body, :text, :null => true
t.column :required, :tinyint, :null => false, :default => ‘0’
t.column :demographic, :tinyint, :null => false, :default
=> ‘0’
t.column :image, :text, :null => true
end
end
# right now we are displaying this flash for debugging purposes
will probably remove it in the near future
flash[:notice] = ‘Item was successfully created.’
$itemnew = @item
redirect_to :action => ‘page2’
else
render :action => ‘new’
end
end
I am creating $itemnew as i could not get the item to pass on to the
page2 action any other way. that code is here (this is where I have
the problem)
called when the user clicks on next from the first page
def page2
@generic_elements = GenericElement.find(:all)
@newitem = Item.find(:first,
:conditions => “id = ‘#{$itemnew.id}’ and user_id =
‘#{@user.id}’”)
itemtablename = “Item_#{@newitem.id}”
#ItemDesign.new(“Item_#{@newitem.id}”)
@itemdesigns = ItemDesign.find_all_elements(itemtablename)
render :action => ‘page2’
end
Now the ItemDesign is a model class that i created myself right now
it looks like this in its entirety:
class ItemDesign < ActiveRecord::Base
attr_accessor :table_name
def self.find_all_elements(table_name)
@table_name = table_name
find_by_sql(“select * from ?”, @table_name)
end
end
The problem is that I am getting the wrong number of arguments (2 for
- error that is in the subject. I have tried an initialize
definition in the model class as well as just about everything else
that I can think of, which is not much since this is my first time on
rails.
Any help is greatly appreciated I really love the language and am
hopefully going to be able to contribute with answers to the list soon.
Andrew