Rails有一段时间的嵌套资源,并且它被大量使用(或过度使用).假设我们有两个模型,文章和评论.
class Article < ActiveRecord::Base
has_many :comments
end
class Comment < ActiveRecord::Base
belongs_to :article
end
Run Code Online (Sandbox Code Playgroud)
在routes.rb中定义嵌套资源
resources :articles do
resources :comments
end
Run Code Online (Sandbox Code Playgroud)
现在,我们可以按特定文章列出评论: http:// localhost:3000/articles/1/comments
但Spine只能为帖子请求制作网址,以便像这样创建文章和评论:
/articles
/comments
Run Code Online (Sandbox Code Playgroud)
如何制作Spine的Ajax请求这样的URL?
/articles/1/comments
Run Code Online (Sandbox Code Playgroud)
我知道我可以在Comment Model中覆盖url()以获取检索注释,但是创建新记录呢?
我也经历了源代码,我发现Spine的Ajax模块中的create()方法并不关心Comment实例中的自定义url()函数.我想要的只是传递article_id并将其与我的自定义url()函数一起使用来生成url,然后我可以发布到服务器进行创建.
没有叉子和Spine的修改版本我自己可以吗?
顺便说一句:对不起我的英文,希望你们所有人都能理解我想说的话:-)
感谢你并致以真诚的问候,