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。 在
CustomSerializer
或Article
模型中实现它的最佳方式是什么?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 presentI need articles in order by poster presence: 1,3,4,2. What is the best way to implement it in
CustomSerializer
or inArticle
model?
原文:https://stackoverflow.com/questions/41333422
最满意答案
将文件放在/ 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.
相关问答
更多-
红帽linux下文本编辑的命令是什么?[2022-08-28]
vim -
vim-latex配置(vim-latex config)[2021-04-02]
在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 ...
-
删除额外的Vim Latex菜单(Delete extra Vim Latex menus)[2022-03-30]
您可以使用:unmenu删除菜单项。 尝试:help :unmenu获取详细信息。 You can use :unmenu to remove menu items. Try :help :unmenu to get the details. -
Vim和Latex-Suite(Vim and Latex-Suite)[2023-08-25]
作为一个实用的解决方案,为什么不将\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 ...
-
Vim乳胶套件没有正确改变环境。(Vim latex-suite is not changing the environment properly. How can I fix this?)[2024-04-19]
我相信这是一个旧的乳胶套件错误。 不确定它是否已在最新版本中修复(已被报道),但无论如何转到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 ...