Hello
I have 2 models.
link.rb
has_many :categories, :as => :categorized
validates_presence_of :name, :url, :created_at, :category
category.rb
belongs_to :categorized, :polymorphic => true
validates_presence_of :name
Everything seems to work. I select my category from a select tag. The
problem is i don’t know how to validate if category is for example empty
(nothing in a select tag), i would like to display the validation error
along with other validation errors for link.
My create method from links_controller.rb
def create
@link = Link.new(params[:link])
if @link.save
flash[:notice] = 'Link was successfully created.'
category = Category.new(params[:category][:id])
category.categorized = @link
category.save
else
render :action => "new"
end
end