I want to pass an array of custom objects to the view layer to render. Rails expects to be able to call "model_name" and a bunch of other methods for routing on its models.
开发者_开发百科If I want to make a custom class that I can pass to methods like "render", what methods does it need to respond to?
Ideally I would like these objects to be usable outside rails as well.
If you are using Rails 3 then it might be worth extending ActiveModel
.
See these posts for more info:
- ActiveModel: Make Any Ruby Object Feel Like ActiveRecord
- Rails 3.0′s ActiveModel: How To Give Ruby Classes Some ActiveRecord Magic
精彩评论