Tag: 嵌套的

在嵌套资源中自动添加父模型ID

使用Rails 3中的嵌套资源路由,如下所示: resources :magazines do resources :ads end 我已经定义了诸如magazine_ad_path类的助手,我必须同时传递杂志和广告,如果我只是引用了广告,这是不方便的: magazine_ad_path(@ad.magazine, @ad) 有没有一种很好的方法来设置一个ad_path帮助器,它接受@ad并返回包含杂志ID的相应地址? (这样也可以使用link_to @ad , redirect_to @ad等,它会自动调用与模型类对应的ad_path助手。)