Take the 2-minute tour ×

Say I have a model Banner. I want the user to be able to upload 2 banners - featured, side.

Am I better off just creating a Banner_Type model or should I just add a type attribute to my Banner model?

If I am just adding a type attribute, how will I then query for those types?

What would the view look like, and the controller.


share|improve this question

closed as not constructive by Deefour, kazanaki, Linger, Tomasz Wojtkowiak, César Bustíos Dec 17 '12 at 15:10


1 Answer 1

up vote 1 down vote accepted

I think the right way is create a banner_type model, coz it gives your the flexibility to add more banner types in future,

My suggestion is the as follows

=== tables ===========


#your banner columns

=== models ==========

class BannerType < ActiveRecord::Base

  has_many :banners


class Banner < ActiveRecord::Base

  belongs_to :banner_type


==== controller ===================

I'm not sure what you asked about the controller, but it will be just as normal controllers.

==== view ========

you could call the banner type as , say you have a banner list

@banners.each do |banner|
    <%= banner.banner_type.type%>


share|improve this answer
This is EXACTLY what I decided to go with before u posted it. Thanks for the confirmation though. –  marcamillion Dec 17 '12 at 6:18
@marcamillion, glad to help, rails rocks !!!! –  sameera207 Dec 17 '12 at 6:23
