Ruby on Rails - Belongs_to and Active Admin not creating foreign ID
        Posted  
        
            by 
                Milo
            
        on Programmers
        
        See other posts from Programmers
        
            or by Milo
        
        
        
        Published on 2014-08-18T19:31:21Z
        Indexed on 
            2014/08/18
            22:31 UTC
        
        
        Read the original article
        Hit count: 551
        
ruby
|ruby-on-rails
I have the following setup:
class Category < ActiveRecord::Base
 has_many :products
end
class Product < ActiveRecord::Base
         belongs_to :category
         has_attached_file :photo, :styles => { :medium => "300x300>", :thumb => "200x200>" }
         validates_attachment_content_type :photo, :content_type => /\Aimage\/.*\Z/     
 end
ActiveAdmin.register Product do
   permit_params :title, :price, :slideshow, :photo, :category
   form do |f|
     f.inputs "Product Details" do
       f.input :title
       f.input :category
       f.input :price
       f.input :slideshow
       f.input :photo, :required => false, :as => :file
     end
     f.actions
   end
   show do |ad|
     attributes_table do
       row :title
       row :category
       row :photo do
         image_tag(ad.photo.url(:medium))
       end
     end
   end
   index do
        column :id
        column :title
       column :category
        column :price do |product|
          number_to_currency product.price
        end
        actions
    end
class ProductController < ApplicationController
     def create
       @product = Product.create(params[:id])
     end
end
Every time I make a product item in activeadmin the category comes up empty. It wont populate the column category_id for the product. It just leaves it empty. What am I doing wrong?
© Programmers or respective owner