开发者

Nested Resources Routing with Plain-Ruby-Object Resources

Having:

class User < WsBasedPlainRubyObject
  def 开发者_StackOverflow中文版subscriptions
     Subscription.where(:user_id=>self.id)
  end

  [...]
end

class Subscription < ActiveRecord::Base
  has_user #using an underlying composed_of
  [...]
end

resources :users do
  resources :subscriptions
end

When I try to use the helper method user_subscriptions_path(@current_user) on the view, params[:user_id] content contains the user's serialization instead of its id.

Is there any practical way to avoid this, maybe by using ActiveModel ?


Apparently, user_subscriptions_path(@current_user.id) works fine..

Anyway, here goes a nice writeup on how to make Ruby objects behave like ActiveRecord Objects by using ActiveModel: ActiveModel: Make Any Ruby Object Feel Like ActiveRecord

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜