开发者

Rails: Using custom classes in Rails

开发者 https://www.devze.com 2023-03-10 04:59 出处:网络
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. 开发者_开发百科

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
0

精彩评论

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