开发者

Trying to make sure I am modeling cleanly

I will try to explain this in a different way so it makes more sense. In my system there are courses which are made up of steps. There are many types of steps: Video, Quiz, Text, Survey...etc. Each of these steps share common data such as title, summary, client, and position. But each step has a completely different model for its data. A quiz step has many different tables and fields where a Text step, really just has one extra field. Therefore I don't think Single Table inheritance works.

But the problem comes when I w开发者_JAVA技巧ant to view all the steps at once and display and edit link.

Since I have different controller for each step type, I don't want to do something like this in my controller:

if @step.type=="Quiz"
   edit_step_quiz_path(@step.getSpecificStepObject())
elsif @step.type == "Text"
   edit_step_text_path(@step.getSpecificStepObject())
elsif @step.type=="Video"
   edit_step_video_path(@step.getSpecificStepObject())
end

Should I instead have my main "step" controller's edit method do the logic and redirect to the appropriate location for editing so my view is clean?


I'm assuming you meant that you are considering putting that code in your view, not your controller. I would define a helper method:

def edit_step_path(step)
  send("edit_step_#{step.type.downcase}_path".to_sym, step.getSpecificStepObject)
end

Then you can just call edit_step_path(@step)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜