"Practical JRuby on Rails Web 2.0 Projects: Bringing Ruby on Rails to Java"
rhtml again and add this code after the part that displays the product type:
<%= render :partial => 'categories' %>
Notice that you??™ve added a span that is empty, and a div tag that contains the output generated from the partial. You??™ll need these two elements later on for the Ajax-y parts of the system. But right now, you need to alter the products_controller.rb again, to make sure everything will be saved when you save a product. This is a little bit outside the box, because Rails doesn??™t handle these multiple selections out of the box. In the create method, you need to add this code directly after the call to Product.new: if params[:product_categories] @product.product_categories << ProductCategory.find( params[:product_categories].collect(&:to_i)) end This code adds all product_categories to the product, if there are any. You need to change the update method a little bit more, because you now have to make sure validation takes place. The new update method should look like this: def update @product = Product.find(params[:id]) intern_price if @product.update_attributes(params[:product]) if params[:product_categories] @product.product_categories = ProductCategory.find( params[:product_categories].collect(&:to_i)) end if @product.save flash[:notice] = 'Product was successfully updated.' redirect_to :action => 'show', :id => @product end end if !@product.