这两个人做同样的事吗?
<%= link_to "Example", '#', class: "somestyle" %>
<a href="#" class= "somestyle"> Example </a>
如果我正在编写一个静态的.html.erb页面,如果其他所有内容都是用HTML标记编写的,那么对于链接使用HTML标记也没有意义吗?我不确定为什么要使用帮手.同样,用于链接样式表,javascripts等.
试图为ember-cli应用程序设置后端.以下是Ember模型的样子:
post.js
export default DS.Model.extend({
heading: DS.attr('string'),
content: DS.attr(''),
imageUrl: DS.attr('string'),
pageId: DS.belongsTo('page'),
tagIds: DS.hasMany('tag')
});
Run Code Online (Sandbox Code Playgroud)
tag.js
export default DS.Model.extend({
name: DS.attr('string'),
postIds: DS.hasMany('post')
});
Run Code Online (Sandbox Code Playgroud)
Rails和Active Record中的模型只是Post,Tag和Theme.主题加入帖子和标签.(即:发布has_many:标签,通过:: themes)
这是我的序列化工具的样子:
class PostSerializer < ActiveModel::Serializer
embed :ids, include: true
attributes :id, :heading, :content, :image_url
has_many :tags
end
class TagSerializer < ActiveModel::Serializer
embed :ids, include: true
attributes :id, :name
end
Run Code Online (Sandbox Code Playgroud)
这在一个方向上起作用:搜索帖子也将获得所有标签.不能在另一个中工作,因为我在TagSerializer中没有has_many.但是,如果我在两个序列化程序中都放置了has_many,则会出现堆栈级别太深的错误.
所以我想我的问题是:与ActiveModel序列化器实现多对多关系的典型方法是什么?我似乎无法找到任何有关如何在Rails后端设置它的资源.任何帮助,将不胜感激.谢谢!