如何制作死链接记者?
我想在我的网站上创建一个按钮,用户可以单击该按钮来报告外部死链接。 我的项目表中的链接列中有该链接。
我想创建一个简单的电子邮件通知,其中包含项目 ID 和链接。 我正在考虑创建一个表单和某种可以处理该表单的控制器。
我的视图应该是这样的:
<% for items in @items %>
<%= simple_form_for @items] do |f| %>
<%= f.hidden field :id, :value => 'item.id' %>
<%= f.hidden field :url, :value => 'item.link %>
<%= f.button :submit, :value => 'report broken link' %>
<% end %>
<% end %>
id 和 url 输入不应该只是像“报告损坏的链接”这样的链接可见。控制器应该获取这两个参数并向我发送电子邮件。
如何创建一个简单的死外部链接报告器?
I want to make a button on my website that a user can click on to report at external dead link.
The link do I have in my link column that is in my item table.
I want to create an simple email notice that have the ID of the item and the link.
I was thinking creating an form and some sort of controller that could handle the form.
My view should look something like this:
<% for items in @items %>
<%= simple_form_for @items] do |f| %>
<%= f.hidden field :id, :value => 'item.id' %>
<%= f.hidden field :url, :value => 'item.link %>
<%= f.button :submit, :value => 'report broken link' %>
<% end %>
<% end %>
The id and the url inputs should not be viewable just a link like "report broken link". A controller should take the two params and send me an email.
How do I create a simple dead external links reporter?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您的问题可能更具体一些,但您可能想使用类似
Net:HTTP
的内容以及类似的内容:Your question could be a bit more specific, but you probably want to use something like
Net:HTTP
and something similar to this:对于一个简单的断开链接报告器,我只会使用干代码的帮助程序,如下所示:
我建议您不需要使用表单,但如果您愿意,可以修改帮助程序。添加/删除您认为合适的参数,但项目 ID 可能足够简单,您可以在后端查找实际链接。只需在您的视图中使用它:
使用一些 ujs 以确保他们不会重新发布它:
希望这有帮助。
For a simple broken link reporter I would just utilize a helper for dry code, like the following :
I suggest that you wouldn't need to use a form, but if you feel so inclined you can modify the helper. Add/remove parameters as you see fit, but the item id would probably be simple enough, you can lookup the actual link in the back end. Simply use it in your views :
Use some ujs to make sure they don't repost it :
Hope this helps.
看来您只是希望您的用户能够报告无效链接而不进行实际检查。你不需要一个表单,一个
应该就足够了,更不用说它看起来更好并且导致更少的样式问题等。在 Rails 3 中,这看起来会有所不同,我认为
:remote=>true
而不是:method=>:post
。您使用此
link_to
调用的控制器/操作应该构造并发送邮件(阅读有关ActionMailer
)。事实上,正如 M. Kohl 所建议的那样,该控制器实际上可以检查链路是否已失效。请注意,您可以传递多个
:controller
、:action
和:id
。您传递的所有内容都将在控制器/操作的params
数组中可用。It seems that you simply want your users to be able to report dead links without doing the actual check. You do not need a form for that, a
should be sufficient, not to mention that it would look nicer and cause less problems with styling, etc. In Rails 3 this would look different, I think
:remote=>true
instead of:method=>:post
.The controller/action you call with this
link_to
should construct and send mail (read aboutActionMailer
). In fact, this controller can actually check whether the link is dead or not, as M. Kohl suggested.Note that you can pass more than
:controller
,:action
and:id
. All of what you pass will be available in theparams
array in the controller/action.正如您所解释的,您只需要一个 发送邮件的邮件程序用户报告损坏的链接,没有什么异常。
其他选项包括创建一个 rake 任务来迭代链接并报告损坏的链接,其代码类似于 Michael Kohl。这不需要用户触发邮件程序:
As you are explaining it, you just need a mailer that sends user reported broken links, nothing unusual.
Other options include creating a rake task which iterates over your links, and reports broken ones, with code similar to Michael Kohl. This doesn't require a user triggered mailer: