Wednesday, 15 April 2015

Rails View and Controller Design for extensible polymorphic resource -



Rails View and Controller Design for extensible polymorphic resource -

i have model, card, belongs through evaluable polymorphic association content1 , content2 (content1 , content2 both have has_one :card, as: :evaluable). also, card belongs_to :list, contents have virtually 1 list through card.

content1 , content2 resources: can created , updated through form user. in views, create possible edit list. example, view creating content1 allow give name of list associated content1 though card.

i allow developers to extend contents ignoring much possible card , list stuffs, in framework fashion. ideally, write part of views related content itself, , included in view list related fields.

on controller side, moment, each contents has own controller, implement 2 methods, evaluable_params (which parses params related content model) , evaluable_model (which returns model class). actions inherited abstract controller uses 2 methods in implementation.

it works pretty since controller code each contents short , not require know rest of app except content model. i'm not sure rails way things, , maybe hard extend other kinds of contents.

so main problem @ time on view side: contents have own controllers , own view.

is possible integrate views include list fields, without contents controllers , view knowing there list model ? is controller inheritance sustainable design ? there other solutions ?

i guess problem not particular, lack of right terminology or keywords or rails knowledge. i'd grateful indication, or feedbacks people who'd have experienced similar problem.

thanks help!

for lack of answer, i'll give thoughts:

--

"content"

in opening, refer content1 , content2 models

then farther through question, refer contents. suggests me content1 , content2 in fact same info - described differently

if case, may wish utilize sti (single table inheritance)

--

sti

this allows set single model, , have others inherit it:

#app/models/content.rb class content < activerecord::base has_one :card, as: :evaluable end #app/models/content_1.rb class content1 < content belongs_to :content, as: :evaluable end

this allow maintain single table content, , populate many different content types like:

#contents id | type | etc | created_at | updated_at

your content1, content2 etc models deed normal models:

@content1 = content1.first

controller

in terms of controller setup, have remember rails built on mvc programming pattern:

this means controller setup near of import model structure. controllers middleman between user's interaction (through view), , app's dataset through models.

if you're worried controllers not beingness set correctly, need appreciate help compile & send requests model. in sense of wondering whether lists or contents controllers need built, have consider way scheme going utilize them

ruby-on-rails design model-view-controller

No comments:

Post a Comment