Checkbox habtm validation problems

I went here-

http://wiki.rubyonrails.org/rails/pages/CheckboxHABTM

to find out how to do multiple checkboxes with a many-to-many
relationship. The problem I am having is that there are other fields in
the form which belong to other tables and I am trying to validate
everything. There is no problem validating, but when the fields in the
other tables aren’t validated the checkboxes are all unchecked if the
user checked the boxes. The way I went about it is that I did a
flash[notice] for the checkboxes and regular validation functions for
the rest of the fields. I have done it in edit and it seems to work but
not add. Here is my code:

View:

<% @ctcount = 1 %> <% @checked = ''%> <% CategoriesTopics.find(:all).each do |@g| %>
										<% if CategoriesTopicsItem.find(:all, :conditions => [ 

“categories_topic_id = ? and item_id = ?”, @g.id, @item.id]).empty? %>
<% @checked = nil %>
<% else %>
<% @checked = ‘checked’ %>
<% end %>
<%if @ctcount == 1%>



<%elsif @ctcount == 2 %>

<%elsif @ctcount == 3 %>


<%else%>

										 <td valign="top" width="156"><p><%= 

check_box_tag(“item[categories_topic_ids][]”, @g.id,
@item.categories_topics.include?(@g), :checked => @checked) %>
<%= @g.topic.topicTitle
%>

												<%end%>
												<% @ctcount = @ctcount + 1 %>
												<% if @ctcount == 3 %>
												<% @ctcount = 1 %>
												<% end %>

												<% end %>
											</table>

controller:

def new
@item = Item.new
@itemphoto = Itemphoto.new

end

def create

  @item = Item.new(params[:item])
  @itemphoto = Itemphoto.new(params[:itemphoto])




  if !params['item']['categories_topic_ids']


    flash[:notice] = 'You must provide at least one cause'
    render :action => 'new', :item => @item, :itemphoto => 

@itemphoto, :categories_topic_ids =>
params[‘item’][‘categories_topic_ids’]

   elsif params['item']['categories_topic_ids'].length > 3


    flash[:notice] = 'Please provide 3 or fewer causes'
   render :action => 'new', :item => @item, :itemphoto => 

@itemphoto, :categoriestopics => params[‘item’][‘categories_topic_ids’]
else

if @item.save && @itemphoto.save
  @item.save
  @item.update_attribute("dateadded", Date.today)
  @item.update_attribute("datemodified", Date.today)

  @items_nonprofits = ItemsNonprofits.new
  @items_nonprofits.update_attribute("nonprofit_id", 

@session[‘user’].nonprofit_id)
@items_nonprofits.update_attribute(“item_id”, @item.id)

  @itemphoto.save
  @itemphoto.update_attribute("item_id", @item.id)
 #  Item.find(@item.id).update_attributes(params[:item])


  flash[:notice] = 'Item was successfully created.'
  redirect_to :action => 'list'

<%=
check_box_tag(“item[categories_topic_ids][]”, @g.id,
@item.categories_topics.include?(@g), :checked => @checked) %>
<%= @g.topic.topicTitle
%>

<%=
check_box_tag(“item[categories_topic_ids][]”, @g.id,
@item.categories_topics.include?(@g), :checked => @checked) %>
<%= @g.topic.topicTitle
%>

<%=
check_box_tag(“item[categories_topic_ids][]”, @g.id,
@item.categories_topics.include?(@g), :checked => @checked) %>
<%= @g.topic.topicTitle
%>