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
精彩评论