English 中文(简体)
以铁路舱位为模型取代“垂直”
原标题:Replace twitter-like usernames in a model s attribute automatically in Ruby on Rails

我花了非常艰难的时间,试图说明如何以这种方式做到这一点。 我有<条码>Comment模型,有<条码>。 这一特性可包含下列内容:

Hi! 这里我提到“@”。

Everytime someone posts a comment, an accessor method in the model converts all @mention to something like #user:231# where 231 would be the user s id. This way, if the mentioned user changes their username, I can still link & mention him without problems on older comments.

现在,我希望能够查阅<条码> ——<>第>条/代码>,并查阅已经转换成链接的提及。 看来,从我所调查的模型中看,不可能以MVC的方式这样做。

这样做是否容易? 我无需改写控制器上的所有提及,因为我认为这可能会导致重复的法典和不可测试的法典。

没有人会就此向我提出一些建议?

感谢!

问题回答

将电文打成一种特定格式,然后在数据库中重新予以保存,然后在稍后日期对其进行编辑。 我感到非常ry,但这样做从根本上说是出于一个原因: 当用户稍后将电文贴上电文时,他们就会看到格式格式文本,除非你格式。 你们是否真的想要对此负责?

我希望不要。 由于你再次担任方案管理员,你自然会 la,希望尽可能少地做事。

我建议为解决这一问题做的是,当你在网页上显示这一信息时,将这一信息抹去。 在你向我发出警告之前,如果你听到我的话,就算是密集的。 当你在网页上展示时,你可以这样做:

<% cache comment do %>
  # code goes here
<% end %>

它将使用包括<条码>号评论在内的藏匿钥匙,在你与铁路公司(可能包括Memcastal)或红海建立起来的任何海滩上储存最后产出<>。 注意这一点以后是有用的。

Retrieval from this cache will be faster than parsing it, and will be easier for you than to convert the message back and forth between its versions.

When a comment is updated, the updated_at timestamp will be different and so the new comment will be rendered first, then cached. In Memcached (so I m told) it will clear the oldest cache key that hasn t been referenced if it needs more memory, thereby cleaning out the older comments.

您是否最终将原始信息搁置起来? 请允许我说一下,我最初的行文是:

"Hi! This is me mentioning @bob."

根据我的理解,你希望把这储存在:

“Hi! 这是我提到的“用户:1#”

现在,如果想把他的用户名称改为“冒犯”,那么我的信息现在就这样:

“Hi! 我指的是“@fred”

简单地在所提及信息与用户之间储存许多对人的关系可能比较容易。 这样,你仍然能够轻易地看到哪条信息提到某个特定用户,但你不需要把原来的信息引向来。

如果你需要将每一字改成一个链接,那么你可以下令把关系表中的条目放在电文中。

maybe this gem help you https://github.com/twitter/twitter-text-rb

第一,includewit:Autolink模块,来自贵班或助手

module ApplicationHelper
  include Twitter::Autolink
end

From views, you can call it by :

<%= auto_link("Hi @john_doe, welcome to #ruby") %>

该系统将产生与Vit john_doeusername and Mouy hashtag的联系。





相关问题
rails collection_select vs. select

collection_select and select Rails helpers: Which one should I use? I can t see a difference in both ways. Both helpers take a collection and generates options tags inside a select tag. Is there a ...

SSL slowness in EC2

We ve deployed our rails app to EC2. In our setup, we have two proxies on small instances behind round-robin DNS. These run nginx load balancers for a dynamically growing and shrinking farm of web ...

Auth-code with A-Za-z0-9 to use in an URL parameter

As part of a web application I need an auth-code to pass as a URL parameter. I am currently using (in Rails) : Digest::SHA1.hexdigest((object_id + rand(255)).to_s) Which provides long strings like : ...

RubyCAS-Client question: Rails

I ve installed RubyCAS-Client version 2.1.0 as a plugin within a rails app. It s working, but I d like to remove the ?ticket= in the url. Is this possible?

activerecord has_many :through find with one sql call

I have a these 3 models: class User < ActiveRecord::Base has_many :permissions, :dependent => :destroy has_many :roles, :through => :permissions end class Permission < ActiveRecord::...

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

Text Editor for Ruby-on-Rails

guys which text editor is good for Rubyonrails? i m using Windows and i was using E-Texteditor but its not free n its expired now can anyone plese tell me any free texteditor? n which one is best an ...

How to get SQL queries for each user where env is production

I’m developing an application dedicated to generate statistical reports, I would like that user after saving their stat report they save sql queries too. To do that I wrote the following module: ...

热门标签