首页 \ 问答 \ ActiveModel :: Serializer进行排序和序列化(ActiveModel::Serializer sort and serialize)

ActiveModel :: Serializer进行排序和序列化(ActiveModel::Serializer sort and serialize)

例如我有两个activeRecord模型:

class Article < ActiveRecord::Base
  has_one :article_poster
end

class ArticlePoster < ActiveRecord::Base
  belongs_to :article
end

在某些控制器中:

CustomSerializer.new(articles)

CustomSerializer:

class CustomSerializer < ActiveModel::Serializer
end

我有4篇文章,有海报,没有它。 例如:
第一篇文章海报礼物
第二篇文章海报不存在
第三篇文章海报礼物
第4条海报礼物

我需要海报存在的文章:1,3,4,2。 在CustomSerializerArticle模型中实现它的最佳方式是什么?


for example i have two activeRecord models:

class Article < ActiveRecord::Base
  has_one :article_poster
end

and

class ArticlePoster < ActiveRecord::Base
  belongs_to :article
end

In some controller:

CustomSerializer.new(articles)

CustomSerializer:

class CustomSerializer < ActiveModel::Serializer
end

I have 4 articles, with poster and without it. For example:
1st article poster present
2nd article poster NOT present
3rd article poster present
4th article poster present

I need articles in order by poster presence: 1,3,4,2. What is the best way to implement it in CustomSerializer or in Article model?


原文:https://stackoverflow.com/questions/41333422
更新时间:2024-05-13 21:05

最满意答案

将文件放在/ usr / share / vim / vimfiles / ftdetect(用于全局)或.vim / ftdetect(用于本地)中,名为Rnw.vim,如下所示:

" Vim filetype detection plugin
" Language:    sweavefile

autocmd BufRead,BufNewFile *.Rnw set filetype=tex

编辑:我很确定你也可以把这个自动命令放在你的.vimrc中,因为在加载任何文件之前它已经在程序启动时加载了,但是这个目录是文件类型检测的自然场所。

编辑:如果您想给这些文件一些不同于TeX的处理,您可以将文件类型设置为rnw,根据需要将脚本添加到ftplugin,缩进和语法目录,最有可能获取TeX脚本然后自己编写东东。


Put a file in /usr/share/vim/vimfiles/ftdetect (for global) or .vim/ftdetect (for local) called Rnw.vim that looks something like this:

" Vim filetype detection plugin
" Language:    sweavefile

autocmd BufRead,BufNewFile *.Rnw set filetype=tex

Edit: I'm pretty sure you could put this autocommand in your .vimrc too, since that's loaded on program start, before any files are loaded, but this is directory the natural place for filetype detection.

Edit: If you would like to give these files some treatment different from TeX, you could instead set the filetype to rnw, add scripts to the ftplugin, indent, and syntax directories as necessary, most likely sourcing the TeX scripts and then doing your own stuff.

相关问答

更多
  • 在Debian(和Ubuntu)中,Vim插件分两个阶段安装。 首先,插件的文件是从包含该插件的.deb软件包安装的。 其次,这些文件的符号链接是在希望使用该插件的用户的~/.vim目录中创建的。 此步骤应由管理员或用户自己使用vim-addons脚本手动执行。 vim-addons允许检查系统中可用的所有Vim插件(即,从软件包安装)并检查其系统范围和当前用户的状态: $ vim-addons status 要安装插件,请运行该命令 $ vim-addons install latex-suite 最 ...
  • 将文件放在/ usr / share / vim / vimfiles / ftdetect(用于全局)或.vim / ftdetect(用于本地)中,名为Rnw.vim,如下所示: " Vim filetype detection plugin " Language: sweavefile autocmd BufRead,BufNewFile *.Rnw set filetype=tex 编辑:我很确定你也可以把这个自动命令放在你的.vimrc中,因为在加载任何文件之前它已经在程序启动时加载了, ...
  • 自发布这个问题以来,我已经做了一些研究并找到了解决方案。 我必须给我很多(也许都是?)信贷给乔什戴维斯 ,我从他身上获得了大部分的设置。 他指着我踢我的.Rnw文件。 但是,对于一个没有经验的用户来说,我需要一些时间和额外的信息来源。 所以对于其他用户来说,这个概述可能会很有趣。 现在,通过终端中的一些初始设置,我可以在VIM中编辑.Rnw文件,同时观看我的PDF格式。 工作流程: 我在vim中编辑我的.Rnw文件(使用vim-r-plugin和vim-latex-suite) 踢球手看着我的.Rnw文件 ...
  • 也许用: :let @a='' :g/\\\(part\|chapter\|section\|subsection\|subsubsection\|paragraph\|subparagraph\)\>/y A :winc n :put a 也许有一个功能来做到这一点并映射你喜欢的任何东西。 maybe use: :let @a='' :g/\\\(part\|chapter\|section\|subsection\|subsubsection\|paragraph\|subparagraph\)\>/ ...
  • TeX到HTML是一项非常重要的任务,因为TeX非常普遍。 正如@richiemorrisroe所说, mk4ht可以在Windows上使用。 所以是tth (你链接到的Vanderbilt页面上提出的另一种方法)。 我不认为你想在R中编写一个TeX解析器...你能告诉我们为什么你需要一个纯粹的R解决方案吗? 它只是为了让解决方案自成一体吗? 我不认为安装真的很难。 这应该会让你获得大部分的路途...... TTHurl <- "http://hutchinson.belmont.ma.us/tth/tth ...
  • 您可以使用:unmenu删除菜单项。 尝试:help :unmenu获取详细信息。 You can use :unmenu to remove menu items. Try :help :unmenu to get the details.
  • 作为一个实用的解决方案,为什么不将\begin{document}和\end{document}行从header.tex和footer.tex模板移到每个实际文档中? 我知道您可能正在尝试遵循DRY原则,但对于一个诚实地打算编译为文档的TeX文件,我觉得这两个标签实际上应该在该文档中,而不是来自另一个TeX文件。 As a practical solution, why don't you move the \begin{document} and \end{document} lines out of h ...
  • 我厌倦了无法更改noweb-minor-mode-map , ess-noweb-mode-map , local-set-key以及我放弃的任何内容local-set-key ess-noweb-mode-map ,只是删除了ess-indent中的代码并替换了通过( yas-expand ) I got fed up not being able to change the keymap of noweb-minor-mode-map, ess-noweb-mode-map, local-set-key ...
  • 我相信这是一个旧的乳胶套件错误。 不确定它是否已在最新版本中修复(已被报道),但无论如何转到ftplugin/latex-suite/envmacros.vim:281并在每行上用\替换\\为我做了诀窍。 你最终应该: let first = '\begin{' . a:env . '}' let second = '\end{' . a:env . '}' I believe this is an old latex-suite bug. Not sure if it's fixed i ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)